Commit f7616a16 authored by Mart Lubbers's avatar Mart Lubbers
Browse files

fix timeout by checking the socket for errors

In the old situation when the connect didn't immediately return, the
socket was placed in a select.
An error was throws only when the socket was in the exceptset. However,
sockets are only in the exceptset in very particular cases (see man
select). Unable to connect is not one of those cases.

Therefore to actually check if a connection was refused, the error
status must be checked with getsockopt.
parent cf79df7a
......@@ -287,6 +287,17 @@ void os_connectTCP_syncC (int onlyForMac, int doTimeout, unsigned int stopTime,
timeout.tv_usec = (timeoutTicks % 1000)*1000; /* Timeout in microsec's */
noOfWritableSockets = select ((int)client+1,NULL,&writeSet,&exptnSet,&timeout);
int so_error;
socklen_t len = sizeof so_error;
getsockopt(client, SOL_SOCKET, SO_ERROR, &so_error, &len);
if (so_error != 0) {
*errCodeP = 1;
*timeoutExpiredP = 0;
*errCodeP = noOfWritableSockets<0
|| (noOfWritableSockets>0 && FD_ISSET(client,&exptnSet));
*timeoutExpiredP = noOfWritableSockets==0;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment