Understanding and Handling WINSOCK Error 10035


WINSOCK error 10035 ("Operation would block") occurs when a socket is temporarily unable to send or receive data because the system buffer is full. For IPWorks users, with the exception of asynchronous components, you generally do not need to handle this error because the components manage it automatically.

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:

  1. You are trying to send a large amount of data through the socket, causing the system's output buffer to become full.
  2. You are trying to send data through the socket to the remote host, but the remote host's input buffer is full (because it is receiving data slower than you are sending it).

Background of WINSOCK Error 10035

When you send data, it is first passed to the TCP/IP subsystem of your machine (i.e., WINSOCK). The system buffers this data (in the OutBuffer) and begins sending it to the remote host as quickly as possible, which is limited by how fast the receiver can accept it. If the OutBuffer becomes full because you are sending data faster than the system can transmit it, you will receive WINSOCK error 10035.

Optionally Handling WOULDBLOCK

When using IPPort or IPDaemon, handle this condition by catching WINSOCK error 10035 and waiting for the component's ReadyToSend event to fire. This event indicates that the system is ready to send data again. At that time, you can resume sending the remaining data. However, you generally do not need to handle this error because the components manage it automatically.

For example, the C# code below loops until all data has been sent. Under normal conditions, the loop executes only once. However, if the output buffer fills, the SetDataToSend call inside the loop fails with WINSOCK error 10035. The code then waits for the ReadyToSend event (using a boolean flag such as ready) and retries the send operation.

Note

  1. The ReadyToSend event fires only if none of the data was sent (that is, when BytesSent equals 0). If some data was successfully sent, the code should immediately attempt to send the remaining data without waiting for the event.

  2. 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.

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 article please contact our support team at support@nsoftware.com.