From 399fd9478e0f4dd8452d0531f04d354c50c9dbfc Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 26 Apr 2018 09:38:51 +0200 Subject: [PATCH] Restore the existing behaviour of Socket::connect() with a 0 timeout 73ba5999186da82b444472170f7e0ce312ce536b rightly removed the code duplication between `Socket::connect()` and `SConnectWithTimeout()`. Unfortunately the two codes had different behaviours when connecting in non-blocking mode with a timeout value of zero. The first one just returned the socket descriptor on `EINPROGRESS`, rightly assuming that a value of 0 for the timeout meant not to wait for the connection to established, while `SConnectWithTimeout()` did not handle that special case, because it was never called with a value of 0 for the timeout duration. --- pdns/iputils.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pdns/iputils.cc b/pdns/iputils.cc index 5379bc04e5..b3d44f353a 100644 --- a/pdns/iputils.cc +++ b/pdns/iputils.cc @@ -61,6 +61,10 @@ int SConnectWithTimeout(int sockfd, const ComboAddress& remote, int timeout) if(ret < 0) { int savederrno = errno; if (savederrno == EINPROGRESS) { + if (timeout <= 0) { + return ret; + } + /* we wait until the connection has been established */ bool error = false; bool disconnected = false; -- 2.47.2