[Winpcap-users] Tips for a real-time (low latency) application?

Richard Hansen pcap-ri at scientician.org
Thu Jun 15 22:31:32 GMT 2006

Hi all,

I'm new to WinPcap/libpcap and have some questions on how to use WinPcap for a low-latency app.  I'm willing to sacrifice some throughput and CPU usage to improve latency.

I can think of three ways to minimize latency, and I have a bunch of questions related to them:

1.  Use pcap_setmintocopy() to improve real-time responsiveness.  Is there a practical limit to how low I can set this?  Would it be bad to set it to 0?  Also, is there a libpcap equivalent to this?

2.  Make sure pcap_next() returns the instant a packet is available.  I'm somewhat confused about how to_ms affects how pcap_next() returns.  Does it return immediately if a packet is available?  Or is it possible for pcap_next() to wait up to to_ms even if a packet is immediately available?  Is this affected by pcap_setmintocopy()?
    What I would like is a function that returns a packet immediately if one is available, otherwise it will wait up to a specified amount of time for a packet to arrive (and will return the instant a packet arrives).  And -- if at all possible -- I would like it to work on multiple platforms (especially Linux and BSD).  Is this possible?  I am currently setting pcap to non-blocking mode and doing a tight poll, but that pegs the CPU.

3.  Mess with the kernel queue behavior.  It would be nifty if the kernel buffer was a head-drop FIFO queue that automatically dropped packets older than a specified cutoff age.  This way I wouldn't waste time copying stale packets into userspace.  Is this possible without messing with the WinPcap source code?  How does WinPcap's kernel buffer behave?  How does libpcap behave?

Any other suggestions for improving latency would be much appreciated.

Thank you!


More information about the Winpcap-users mailing list