Skip to content

Instantly share code, notes, and snippets.

@theultramage
Last active November 15, 2016 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theultramage/e22b0013407bf85e0ab2cd755ceb1973 to your computer and use it in GitHub Desktop.
Save theultramage/e22b0013407bf85e0ab2cd755ceb1973 to your computer and use it in GitHub Desktop.
this is what I had in mind pull/1714
if( result == SOCKET_ERROR ) {
// That is the error we intend, because we want to use a timeout
if( sErrno != S_EWOULDBLOCK ) {
// All other errors should be reported immediately
if( !silent )
ShowError("make_connection: connect failed (socket #%d, %s)!\n", fd, error_msg());
do_close(fd);
return -1;
}
fd_set writeSet;
struct timeval tv;
sFD_ZERO(&writeSet);
sFD_SET(fd,&writeSet);
tv.tv_sec = timeout;
tv.tv_usec = 0;
// Try to find out if the socket is writeable yet(within the timeout)
if( sSelect(0, NULL, &writeSet, NULL, &tv) == 0 ){
// Our connection attempt timed out
if( !silent )
ShowError("make_connection: connect failed because of a timeout (socket #%d)!\n", fd); // No socket error to report here
do_close(fd);
return -1;
}
// Check if the socket is writeable
if( sFD_ISSET(fd,&writeSet) == 0 ){
if( !silent )
ShowError("make_connection: connect failed (socket #%d, %s)!\n", fd, error_msg());
do_close(fd);
return -1;
}
// Our socket is writeable now => we have connected successfully
}
// Keep the socket in non-blocking mode, since we would set it to non-blocking here on unix. [Lemongrass]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment