diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-04-05 22:19:29 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-04-05 22:19:29 +0200 |
commit | de2a34dc7f2ab04674d974bbdf815af6a1da7a59 (patch) | |
tree | b0e790a3ac63e29d388f8d6451e33a830aa1d14d /tests | |
parent | dd4d5c5ff526a9d4d6c61922b27ae03ce91aa34a (diff) | |
download | wolfbones-de2a34dc7f2ab04674d974bbdf815af6a1da7a59.tar.gz wolfbones-de2a34dc7f2ab04674d974bbdf815af6a1da7a59.tar.bz2 |
changed asynchronous connect strategy, double connect seems more reliable on Linux at least
Diffstat (limited to 'tests')
-rw-r--r-- | tests/network/test1.c | 21 |
1 files changed, 19 insertions, 2 deletions
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( ); |