[英]Winpcap - pcap_next_ex vs pcap_loop
I have a question, Imagine I have a thread which captures packets and process them itself. 我有一个问题,想象一下,我有一个线程可以捕获数据包并自行处理它们。
With pcap_next_ex
: I would use a loop and I would process the packets in each interaction, suppose I call Sleep(200)
to simulate the stuff. 使用
pcap_next_ex
:我会使用一个循环,我会在每次交互中处理数据包,假设我调用Sleep(200)
来模拟这些东西。 With pcap_next_ex
I would arrive a moment when I would lose packets. 使用
pcap_next_ex
我会在丢失数据包时到达。
With pcap_loop
: I would use a callback to a packet handler for each packet incoming it would work like an event. 使用
pcap_loop
:我将对每个数据包使用一个数据包处理程序的回调,它将像一个事件一样工作。 In the packet handler I would treat the packets and suppose I call Sleep(200)
to simulate the stuff. 在数据包处理程序中,我会处理数据包,并假设我调用
Sleep(200)
来模拟这些东西。 Would I lose packets?. 我会丢包吗?
Yes. 是。
pcap_next_ex
and pcap_loop
call the same internal function that reads a packet from the ring buffer. pcap_next_ex
和pcap_loop
调用从环形缓冲区读取数据包的相同内部函数。 The difference is only that the former return the packet but the latter calls a callback with the packet. 不同之处仅在于前者返回数据包,后者则使用数据包调用回调。
pcap_loop
calls the callback in the same thread as one called the pcap_loop
, and waits for the callback to complete its task before reading the next packet. pcap_loop
在与调用pcap_loop
线程相同的线程中调用回调,并在读取下一个数据包之前等待回调完成其任务。 So, if the callback takes a long time, the pcap_loop
cannot read packets enough frequently, which results in more possibility to lose packets. 因此,如果回调需要很长时间,则
pcap_loop
无法经常读取数据包,从而导致丢失数据包的可能性增加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.