本文整理汇总了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();
}