]> granicus.if.org Git - pdns/commitdiff
Restore the existing behaviour of Socket::connect() with a 0 timeout
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Apr 2018 07:38:51 +0000 (09:38 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Apr 2018 07:38:51 +0000 (09:38 +0200)
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

index 5379bc04e5430e9e019f3327c31a66c1d53a501c..b3d44f353acdaef483c971a4d0c439d81b699988 100644 (file)
@@ -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;