10035 WOULDBLOCK error

What is the 10035 WOULDBLOCK error and how do I handle it?

Date Entered: 6/17/2004    Last Updated: 03/25/2014

***Note***

If you are using a .NET, Java, or related IPWorks or IPWorks SSL toolkit, then in addition to the information below, you can set the DefaultTimeout property to a positive value and perform simultaneous sends by utilizing a background thread for each send. This is only possible in .NET and Java because those toolkits are thread-safe.

In the IPWorks and IPWorks SSL toolkits, winsock error 10035 means "Resource not available" or "Operation would block". This error happens when the winsock buffer of either the client or server side become full.

Here are two situations in which you might see Winsock error 10035:

  • You're trying to send a massive amount of information through the socket, so the output buffer of the system becomes full.
  • You're trying to send data through the socket to the remotehost, but the remotehost input buffer is full (because its receiving data slower than you're sending it).
When you send data - you really send it to the TCP/IP subsystem of your machine (ie winsock). The system buffers this data (in the OutBuffer) and begins sending it to the remote host as fast as it can (which of course is only as fast as the receiver can receive it). If the OutBuffer gets filled, because you are sending data faster than the system can send it - you'll get Winsock error 10035.

For IPWorks users, with the exception of asynchronous components like IPPort and IPDaemon, you will never have to worry about this error because the components deal with them for you automatically. The IPPort and IPdaemon components are the building blocks with which you can build any TCP/IP solution, they give you complete control over everything.

In order to deal with this when using IPPort or IPDaemon, just catch the Winsock 10035 error and wait for the component's ReadyToSend event to fire (this fires when the system is able to send data again). At that time, you can continue sending your data, starting with that which failed. For example, the c# code below will loop until the length of the data to be sent is 0. If all goes normally, this loop will only be entered once and all of the data will be sent. After a while, if the output buffer fills up, the SetDataToSend inside the loop will fail with the Winsock 10035 error. The code will wait for the ReadyToSend event (the ready boolean flag), and loop. SetDataToSend will be called again, successfully.

note: The ReadyToSend event will only fire if none of the data was able to be sent. So the code below will only wait for the event if BytesSent equals 0. Otherwise, if some of the data was able to be sent, the code will loop immediately and attempt to resend the remaining data.

while (length > 0) { //this means that we have some bytes to send try { ready = false; ipport1.SetDataToSend(TextB, offset, length); length -= ipport1.BytesSent; tbStatus.AppendText(ipport1.BytesSent.ToString() + " bytes sent." + "\r\n"); } catch (nsoftware.IPWorks.IPWorksException ex1) { if (ex1.Code == 135) //WOULDBLOCK Error { if (ipport1.BytesSent == 0) while (!ready) { ipport1.DoEvents(); } length -= ipport1.BytesSent; offset += ipport1.BytesSent; tbStatus.AppendText("Retrying Send..." + "\r\n"); } } }


We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.