diff --git a/lib/SimpleHttpClient/ClientConnection.cpp b/lib/SimpleHttpClient/ClientConnection.cpp index e0ec1e4dc9..50cf5a0ae6 100644 --- a/lib/SimpleHttpClient/ClientConnection.cpp +++ b/lib/SimpleHttpClient/ClientConnection.cpp @@ -228,12 +228,10 @@ bool ClientConnection::prepare (double timeout, bool isWrite) const { return false; } - struct timeval tv; - tv.tv_sec = (long) timeout; - tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0); - fd_set fdset; - do { + + // handle interrupt + do { FD_ZERO(&fdset); FD_SET(fd, &fdset); @@ -248,15 +246,19 @@ bool ClientConnection::prepare (double timeout, bool isWrite) const { } int sockn = (int) (fd + 1); - res = select(sockn, readFds, writeFds, nullptr, &tv); + + struct timeval t; + t.tv_sec = (long) timeout; + t.tv_usec = (long) ((timeout - TV_SEC) * 1000000.0); + + res = select(sockn, readFds, writeFds, nullptr, &t); + if ((res == -1 && errno == EINTR)) { int myerrno = errno; double end = TRI_microtime(); errno = myerrno; timeout = timeout - (end - start); start = end; - tv.tv_sec = (long) timeout; - tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0); } } while (res == -1 && errno == EINTR && timeout > 0.0); #endif diff --git a/lib/SimpleHttpClient/SslClientConnection.cpp b/lib/SimpleHttpClient/SslClientConnection.cpp index 7becf86653..463d9a3b7b 100644 --- a/lib/SimpleHttpClient/SslClientConnection.cpp +++ b/lib/SimpleHttpClient/SslClientConnection.cpp @@ -322,12 +322,10 @@ bool SslClientConnection::prepare (double timeout, bool isWrite) const { return false; } - struct timeval tv; - tv.tv_sec = (long) timeout; - tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0); - fd_set fdset; - do { + + // handle interrupt + do { FD_ZERO(&fdset); FD_SET(fd, &fdset); @@ -343,7 +341,12 @@ bool SslClientConnection::prepare (double timeout, bool isWrite) const { } int sockn = (int) (fd + 1); - res = select(sockn, readFds, writeFds, nullptr, &tv); + + struct timeval t; + t.tv_sec = (long) timeout; + t.tv_usec = (long) ((timeout - TV_SEC) * 1000000.0); + + res = select(sockn, readFds, writeFds, nullptr, &t); if ((res == -1 && errno == EINTR)) { int myerrno = errno; @@ -351,8 +354,6 @@ bool SslClientConnection::prepare (double timeout, bool isWrite) const { errno = myerrno; timeout = timeout - (end - start); start = end; - tv.tv_sec = (long) timeout; - tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0); } } while ((res == -1) && (errno == EINTR) && (timeout > 0.0));