From de2a34dc7f2ab04674d974bbdf815af6a1da7a59 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 5 Apr 2009 22:19:29 +0200 Subject: changed asynchronous connect strategy, double connect seems more reliable on Linux at least --- tests/network/test1.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/network/test1.c b/tests/network/test1.c index 79e9935..969c405 100644 --- a/tests/network/test1.c +++ b/tests/network/test1.c @@ -187,6 +187,23 @@ CONNECT_SELECT_AGAIN: goto FAIL; } else { if( FD_ISSET( fd, &read_set ) || FD_ISSET( fd, &write_set ) ) { +/* strategy second connect */ +SECOND_CONNECT_AGAIN: + res = connect( fd, result->ai_addr, result->ai_addrlen ); + if( res < 0 ) { + if( errno == EINTR ) { + /* interrupted, no problem, the connection goes on anyway */ + goto SECOND_CONNECT_AGAIN; + } else { + (void)close( fd ); + fprintf( stderr, "second connect failed: %s (%d)\n", strerror( errno ), errno ); + goto FAIL; + } + } + +/* strategy setsockopt and SO_ERROR: + +Not really realiable! Can result 0 though the server is not there! socklen_t sock_error_len; int sock_error; @@ -207,6 +224,7 @@ CONNECT_SELECT_AGAIN: goto FAIL; } } +*/ } else { fprintf( stderr, "Socket not ready after select\n" ); (void)close( fd ); @@ -290,7 +308,7 @@ CONNECTED: if( stdout_to_write > 0 ) { FD_SET( STDOUT_FILENO, &write_set ); } - if( stdout_to_write == 0 ) { + if( !fd_eof && stdout_to_write == 0 ) { FD_SET( fd, &read_set ); } if( fd_to_write > 0 ) { @@ -470,7 +488,6 @@ END: goto OK; FAIL: - freeaddrinfo( result ); #ifdef _WIN32 WSACleanup( ); -- cgit v1.2.3-54-g00ecf