rfc2553_connect_to(): Properly detect and log when poll() reached the time out
authorFabian Keil <fk@fabiankeil.de>
Thu, 8 Jun 2017 13:04:56 +0000 (13:04 +0000)
committerFabian Keil <fk@fabiankeil.de>
Thu, 8 Jun 2017 13:04:56 +0000 (13:04 +0000)
Previously this was logged as:
Could not connect to [...]: No error: 0.
which isn't very helpful.

The select() code path doesn't look like it would handle timeouts
properly either but apparently nobody noticed this yet ...

Sponsored by: Robert Klemme

jbsockets.c

index 3c43c17..7214979 100644 (file)
@@ -1,4 +1,4 @@
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.143 2017/06/04 14:37:05 fabiankeil Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.144 2017/06/08 13:04:34 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
@@ -373,7 +373,26 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client
       poll_fd[0].fd = fd;
       poll_fd[0].events = POLLOUT;
 
-      if (poll(poll_fd, 1, 30000) > 0)
+      retval = poll(poll_fd, 1, 30000);
+      if (retval == 0)
+      {
+         if (rp->ai_next != NULL)
+         {
+            /* Log this now as we'll try another address next */
+            log_error(LOG_LEVEL_CONNECT,
+               "Could not connect to [%s]:%s: Operation timed out.",
+               csp->http->host_ip_addr_str, service);
+         }
+         else
+         {
+            /*
+             * This is the last address, don't log this now
+             * as it would result in a duplicated log message.
+             */
+            socket_error = ETIMEDOUT;
+         }
+      }
+      else if (retval > 0)
 #else
       /* wait for connection to complete */
       FD_ZERO(&wfds);