-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create API calls for non-blocking packet writes #747
Comments
Some thoughts and notes from my research:
|
s;Linux;platforms supporting the POSIX asynchronous I/O interface; Although that requires that the platform's mechanism for transmitting packets also support that interface. (But details such as that probably belong on the libpcap issues list.) |
A customer recently reported a potentially related performance issue. They are framing and sending numerous raw packets at different time intervals ranging from 20ms to 2s. They use pcap_sendpacket in one thread while capturing in an independent thread iwth pcap_loop to check whether they were delivered in the desired time. They noticed that when pcap_loop is enabled, the pcap_sendpacket call to take longer, in turn causing delayed sending of packets. They also noticed better performance on 32-bit systems than 64-bit ones. |
Npcap offers ways to read packets asynchronously, but packet writes are always blocking. We basically use the Windows version of the UNIX write() syscall. This is because we wait around to ensure the write was successful and return the appropriate error code if not. This usually doesn't take very long, but we did have one Npcap OEM redistribution license customer recently report that it could take up to 3ms and that caused problems for their real-time software.
The simplest approach would be to make all packet writes asynchronous, but that would be problematic for folks who would prefer waiting a millisecond or so to ensure the write was successful. So a better approach would probably be to offer an asynchronous option for those who want it.
We looked at how the (now obsolete) Winpcap system handled it. The system call to give the packet to the driver was synchronous, but the driver called an asynchronous NDIS function and returned immediately. It would give the illusion of being fire-and-forget. You get errors if you did something dumb with the packet structure as defined in Packet.dll API, but you don't get to find out if Windows actually sent your packet. Also the driver also did a wait for an event that the NDIS callback would set, so still it was effectively a blocking call.
Npcap has changed that: the write handler is asynchronous and indicates that to Windows by returning STATUS_PENDING. Then Windows does the work of waiting. That means the way is clear for Packet.dll to use Windows-provided synchronization routines like WriteFileEx and LPOVERLAPPED struct to do the work.
We would want to coordinate with the libpcap team--probably open an issue on their tracker to discuss how they prefer to handle asynchronous calls like this. That way we may be able to get a standardized and cross-platform solution.
The text was updated successfully, but these errors were encountered: