当前位置: 首页>>代码示例>>C++>>正文


C++ Memory::allocate方法代码示例

本文整理汇总了C++中Memory::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ Memory::allocate方法的具体用法?C++ Memory::allocate怎么用?C++ Memory::allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Memory的用法示例。


在下文中一共展示了Memory::allocate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
	}
	if (pcap_setfilter(pcapDescriptor, &bpfProgram) == -1) {
		print_error(argv[0], pcap_geterr(pcapDescriptor));
		return 1;
	}
	/* If running on FreeBSD, puts the BPF device into immediate mode. */
	#ifdef __FreeBSD__
		if (input_files.empty()) {
			if (ioctl(pcap_fileno(pcapDescriptor), BIOCIMMEDIATE, &immediate) == -1) {
				print_error(argv[0], strerror(errno));
				return 1;
			}
		}
	#endif
	if (input_files.empty()) {
		cout << "Capturing on " << interface << '.' << endl;
	}
	else {
		cout << "Reading from " << input_files[0] << '.' << endl;
	}

	/* Starts the stats thread. */
	if (input_files.empty()) {
		pthread_create(&pcapStatsThread, NULL, &getPcapStats, &stats_interval);
	}
	/*
	 * Fills the packet queue with captured packets until the capture variable is
	 * set to false by the signal handler.
	 */
	while (capture) {
		if ((pcapPacket = pcap_next(pcapDescriptor, &pcapHeader)) != NULL) {
			/* Allocates memory for a Packet class using the memory allocator. */
			packetMemory.lock();
			if ((packet = packetMemory.allocate()) == NULL) {
				packetMemory.unlock();
				pthread_mutex_lock(&droppedPacketsLock);
				++droppedPackets;
				pthread_mutex_unlock(&droppedPacketsLock);
			}
			else {
				packetMemory.unlock();
				/*
				 * Initializes the Packet class with information from the captured
				 * packet.
				 */
				packet -> initialize(pcapHeader, pcapPacket, pcapPacketMemory, locks,
														 localNetworks);
				for (size_t moduleGroup = 0; moduleGroup < moduleGroups.size(); ++moduleGroup) {
					for (size_t module = 0; module < moduleGroups[moduleGroup].modules.size(); ++module) {
						modulePtr = &(moduleGroups[moduleGroup].modules[module]);
						/* Checks if a module is interested in the packet. */
						if (bpf_filter(modulePtr -> bpfProgram().bf_insns,
													 (u_char*)pcapPacket, pcapHeader.len,
													 pcapHeader.caplen) != 0) {
							/* Increments the packet's reference count. */
							packet -> lock();
							packet -> reference();
							packet -> unlock();
							/* Adds a pointer to the packet to the module's packet queue. */
							modulePtr -> packetQueue.lock();
							modulePtr -> packetQueue.push(packet);
							modulePtr -> packetQueue.unlock();
							moduleGroups[moduleGroup].lockQueueSize();
							moduleGroups[moduleGroup].incrementQueueSize();
							moduleGroups[moduleGroup].unlockQueueSize();
						}
开发者ID:derrick0714,项目名称:infer,代码行数:67,代码来源:sensor.cpp


注:本文中的Memory::allocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。