From c112a4a797c74fb19a06e105c7f832759863d3d5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 21 Jul 2020 16:45:50 +0200 Subject: [SHARED] Fix: connect with timeout returns socket handle on EINPROGRESS Only if we request non-blocking connect (connect_ms == -1) this function should return a socket fd that is not actually connected. Otherwise, consder this a failure, close the sock fd, and return -1. --- src/shared/sockhelper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/shared') diff --git a/src/shared/sockhelper.c b/src/shared/sockhelper.c index ab34aa1..582420a 100644 --- a/src/shared/sockhelper.c +++ b/src/shared/sockhelper.c @@ -58,7 +58,7 @@ int sock_connect(const dnbd3_host_t * const addr, const int connect_ms, const in } for ( int i = 0; i < 5; ++i ) { int ret = connect( client_sock, (struct sockaddr *)&ss, addrlen ); - if ( ret != -1 || errno == EINPROGRESS || errno == EISCONN ) break; + if ( ret != -1 || ( connect_ms == -1 && errno == EINPROGRESS ) || errno == EISCONN ) break; if ( errno == EINTR ) { // http://www.madore.org/~david/computers/connect-intr.html #ifdef __linux__ -- cgit v1.2.3-55-g7522