I've a multi-treaded Windows 2003 Server application that sends and receives UDP packets at a high rate and over a single socket. The socket is configured to work in non-blocking mode and several threads may call the sendto() function over this socket, though there is only thread that reads from the socket. When the application calls sendto() at a very high rate that exceeds a certain threshold, we see that calls to sendto() start failing with the error code 10035 (function would block). The threshold seems to be the point where the sendto() gets called at around 7500 times per second. At this time, the application is receiving data at around the same rate, however, the recv() function works fine. Windows reported network usage at this point is around 30 mbps, or 30% on our 100 mbps fast ethernet. CPU usage on our quad-code box is around 70% at this point. Suspecting a LAN or NIC problem, I tried to run this application along with its client on the same box so that we have no actual traffic going through the NIC to the LAN. I got the same result in this test and sendto() started failing at around the same point. I'll appreciate if anyone can help me with this issue.
You're going to have to wrap your sendto() calls with a mutex or a critical section. It is not possible for more than one thread to call sendto() at the same time on the same socket. They are colliding at the rate you're sending data over the socket.
Thanks. I used to think that socket function calls are thread-safe. Anyway, I followed your advice, and had the sendto() function calls enclosed in critical_section. However, I'm still experiencing this issue.
And your still getting the error 10035? I'm not sure, but then again, I've never tried to pump that many data through a UDP socket before. Perhaps it is a limitation of the TCP/IP stack or the network itself.