Index: src/vortex_connection.c =================================================================== --- src/vortex_connection.c (revision 3242) +++ src/vortex_connection.c (working copy) @@ -1231,27 +1231,29 @@ /* if a connection timeout is defined, wait until connect */ if(d_timeout) { - /* create a waiting set using current selected I/O - * waiting engine. */ - on_writing = vortex_io_waiting_invoke_create_fd_group (WRITE_OPERATIONS); - vortex_io_waiting_invoke_clear_fd_group (on_writing); + /* create a waiting set using current selected I/O waiting engine */ + on_writing = vortex_io_waiting_invoke_create_fd_group (WRITE_OPERATIONS); + while( d_start_time + d_timeout > time(NULL) ) { + int done; + vortex_io_waiting_invoke_clear_fd_group (on_writing); + done = vortex_io_waiting_invoke_add_to_fd_group(connection->session, connection, on_writing); + if( !done ) break; + err = vortex_io_waiting_invoke_wait(on_writing, connection->session, WRITE_OPERATIONS); + switch( err ) + { + case 0://select, poll, epoll timeout + case -1://EINTR + case -2://SSL + done = false; + break; + case -3://fatal internal error + default://other errors or success + done = true; + break; + } + if( done ) break; + } - /* add the socket in connection transit */ - if (vortex_io_waiting_invoke_add_to_fd_group (connection->session, connection, on_writing)){ - - while (d_start_time + d_timeout> time (NULL)) { - err = vortex_io_waiting_invoke_wait (on_writing, connection->session, WRITE_OPERATIONS); - - if(err == -1 /*EINTR*/ || err == -2 /*SSL*/) - continue; - else if (!err) - continue; /*select, poll, epoll timeout*/ - else if (err>0) - break; /*connect ok*/ - else if (err /*==-3, fatal internal error, other errors*/) - break; - } /* end while */ - } /* end if */ if(err <= 0){ /* timeout reached while waiting for the connection to terminate */