From: Remi Gacogne Date: Thu, 26 Apr 2018 07:38:51 +0000 (+0200) Subject: Restore the existing behaviour of Socket::connect() with a 0 timeout X-Git-Tag: dnsdist-1.3.1~127^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=399fd9478e0f4dd8452d0531f04d354c50c9dbfc;p=pdns 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. --- diff --git a/pdns/iputils.cc b/pdns/iputils.cc index 5379bc04e..b3d44f353 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;