WSAEWOULDBLOCK and WSAEISCONN
Hello.
I wrote this code:
Code:
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in socket_address;
//snip - initialize the socket_address' members - snip//
int status = 1;
ioctlsocket(sock, FIONBIO, &status); //set the socket in non-blocking mode
while (1)
{
int ret = connect(sock, (sockaddr*)(&socket_address), sizeof(socket_address));
if (ret == -1)
{
cout << "Connection error : " << WSAGetLastError() << endl;
Sleep(50); //wait a bit to not hang the CPU
}
else
{
cout << "Connection succeeded" << endl;
break;
}
}
I get this output:
WSAEWOULDBLOCK - the connect function would block, try again later
WSAEISCONN - the socket is already connected, why are you trying to connect it again?
(ofcourse the output is written in numbers, but I translated the error codes and added my comments on what they mean imho).
So, what's wrong(firt it says: try again later, but later, it says that the socket is already connected)?