Jim Newtron
Jim Newtron

Reputation: 227

WSAEWOULDBLOCK error on non-blocking Connect()

I am trying to connect to a server on another machine via a non-blocking connect().

However, when I do so, Connect() returns -1, and I receive WSAEWOULDBLOCK from WSAGetLastError().

MSDN Documentation states that: 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 (reference).

The issue is that I am always receiving the error, and -1 is returned from connect() EVEN IF my server is not running.

My socket is a SOCK_STREAM socket, just as suggested. How might I remedy this? Should I provide a timeout after the connect() call to ensure that enough time is given for connect to establish a connection?

Upvotes: 1

Views: 3894

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283614

Use ConnectEx and pass the OVERLAPPED structure. That way you can retrieve the actual status later, when the connection attempt finishes.

Upvotes: 2

Related Questions