Skip navigation

The docs say:

10035: WSAEWOULDBLOCK.

Resource temporarily unavailable.

This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.

WTF???

wtf indeed

This error isn’t an error at all. Pay attention to the last phrase:

10035: WSAEWOULDBLOCK.

Resource temporarily unavailable.

This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.

In a program, like that crummy msdn example, I wrote:

  // Connect to server.
  if ( connect( g.s, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {
    
    int err = WSAGetLastError();
    printf( "Failed to connect:  Error code: %d.\n", err );
    WSACleanup();
    return;
  }

But what would happen EVERY TIME is 10035: WSAEWOULDBLOCK.

WHY??? I puzzled over this again and again. WHAT IS WSAEWOULDBLOCK??
codegear has:

Abstract: Whenever I try to run my socket program, I get the error WSAEWOULDBLOCK.

Question

Why do I get a WSAEWOULDBLOCK error when I run my program.

Answer

This means that you are setting up your program as a non-blocking sockets program, however the computer is telling you that it would have to create a blocked connection to the socket.

Of all the bullshit…

THAT DOESN’T ANSWER MY QUESTION!!

So, I tried putting it in a loop to see if the state would change:

  // Connect to server.
  while ( connect( g.s, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {
    
    int err = WSAGetLastError();
    printf( "Failed to connect:  Error code: %d.\n", err );
    //WSACleanup();
    //return;
  }

INTERESTINGLY, this is what happens:

10035
10056
10056
10056
10056
10056
10056
10056
.
.
.

Where 10056 is:

10056: WSAEISCONN

Socket is already connected.

A connect request was made on an already-connected socket. Some implementations also return this error if sendto is called on a connected SOCK_DGRAM socket (for SOCK_STREAM sockets, the to parameter in sendto is ignored) although other implementations treat this as a legal occurrence.

WHAT???? WOOHOO . . . ? ITS CONNECTED!!! BUT WHY??

Ah. I get it. Read that red italicized text again:

10035: WSAEWOULDBLOCK.

Resource temporarily unavailable.

This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.

So it would SEEM that since 10035 WSAEWOULDBLOCK is a non-fatal error, you should IGNORE IT TRY AND USE THE SOCKET ANYWAY.

If you want to use an if statement like the crummy MSDN example (which is the reason this took so long to get past!!)

  // Connect to server.
  while ( connect( g.s, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {
    
    int err = WSAGetLastError();
    printf( "Failed to connect:  Error code: %d.\n", err );
    printf( errCodes[ err ] );
    //WSACleanup();
    //return;

    // these errors are non-fatal:  10056 means already connected
    // and 10035 means its trying really hard to connect
    // and you should just give it a moment.
    if( err == 10056 || err == 10035 )
      break;
  }

5 Comments

  1. addendum: it turns out that you’re __SUPPOSED__ to get WSAEWOULDBLOCK if you create a non-blocking socket and try to read from it.

    Also note that in a Network Programming book by Richard Blum he says in his Chapter 3 (about a linux non-blocking socket): “If no data is immediately present, the recv() function will return a value of –1, and the Unix errno value would be set to EWOULDBLOCK.”

    So it seems to me that if you create a non-blocking socket, again EWOULDBLOCK / WSAEWOULDBLOCK isn’t an ERROR. It just means there’s no data for you to read, and that’s winsock’s way of telling you that.

    Kind of like how a socket gives you a 0 length “piece of data” when a client disconnects. Its a signal that means something slightly different than you might originally think.

  2. OK Now I think I understand this:

    The winsock api NORMALLY wants to block on a socket when you call recv().

    To return from recv() __WITH NO DATA__ IS an error.. and the error is simply that “there was no data”

    get it?

    • Anonymous
    • Posted May 24, 2010 at 10:49 am
    • Permalink

    i meet the same problem!

    • Anonymous
    • Posted August 5, 2011 at 1:18 pm
    • Permalink

    You just have to call connect, if you get this blocking error then wait for the FD_CONNECT event to know if it worked

    • Daniel Howard
    • Posted August 13, 2019 at 6:02 am
    • Permalink

    I am trying to do this from visual c++ in a routine reversing endian etc which I picked up from the net. Basically, I am trying ti get the win32.lib time from a server. I built the structure and finding the dns and send of data works but the recv gets me the 10035 so the server is ignoring me. I change the mode and the mode and version in the NTP stucture I am sending (pointed by a char*). It is very frustrating, four days trying. Message always stays at 100035 I loop 1000 times.


2 Trackbacks/Pingbacks

  1. […] resolving winsock error 10035: WSAEWOULDBLOCK | Bobobobo’s Weblog – The docs say: 10035: WSAEWOULDBLOCK. Resource temporarily unavailable. This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. […]

  2. […] resolving winsock error 10035: WSAEWOULDBLOCK | … – Nov 09, 2008 · The docs say: 10035: WSAEWOULDBLOCK. Resource temporarily unavailable. This error is returned from operations on nonblocking sockets that …… […]

Leave a comment