]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Handle partial failures when connecting (Issue #4866)
authorMichael Sweet <michael.r.sweet@gmail.com>
Tue, 20 Sep 2016 19:23:40 +0000 (15:23 -0400)
committerMichael Sweet <michael.r.sweet@gmail.com>
Tue, 20 Sep 2016 19:23:40 +0000 (15:23 -0400)
CHANGES.txt
cups/http-addrlist.c

index 943dca62e2021c2a3205ba09fa3863db09830935..ac92a79929b14d88bc5caf3536929bd7fbcc2abf 100644 (file)
@@ -6,6 +6,7 @@ CHANGES IN CUPS V2.2.1
        - Added "CreateSelfSignedCerts" directive for cups-files.conf to
           control whether the scheduler automatically creates its own
           self-signed X.509 certificates for TLS connections (Issue #4876)
+        - http*Connect did not handle partial failures (Issue #4866)
         - Updated localizations (PR #4877)
 
 
index 6e2ad8196672ac791b4d2bd3d828235e05cdbd49..e9ef53ea43e91c6d8c388c00e3d9a0cd4d535dba 100644 (file)
@@ -304,6 +304,8 @@ httpAddrConnect2(
 
     if (result > 0)
     {
+      http_addrlist_t *connaddr = NULL;        /* Connected address, if any */
+
       for (i = 0; i < nfds; i ++)
       {
 #  ifdef HAVE_POLL
@@ -314,7 +316,7 @@ httpAddrConnect2(
 #  endif /* HAVE_POLL */
        {
          *sock    = fds[i];
-         addrlist = addrs[i];
+         connaddr = addrs[i];
 
 #  ifdef DEBUG
          len   = sizeof(peer);
@@ -322,11 +324,29 @@ httpAddrConnect2(
            DEBUG_printf(("1httpAddrConnect2: Connected to %s:%d...", httpAddrString(&peer, temp, sizeof(temp)), httpAddrPort(&peer)));
 #  endif /* DEBUG */
        }
-       else
+#  ifdef HAVE_POLL
+       else if (pfds[i].revents & (POLLERR | POLLHUP))
+#  else
+       else if (FD_ISSET(fds[i], &error))
+#  endif /* HAVE_POLL */
+        {
+         /*
+          * Error on socket, remove from the "pool"...
+          */
+
          httpAddrClose(NULL, fds[i]);
+          nfds --;
+          if (i < nfds)
+          {
+            memmove(fds + i, fds + i + 1, (size_t)(nfds - i) * (sizeof(fds[0])));
+            memmove(addrs + i, addrs + i + 1, (size_t)(nfds - i) * (sizeof(addrs[0])));
+          }
+          i --;
+        }
       }
 
-      return (addrlist);
+      if (connaddr)
+        return (connaddr);
     }
 #endif /* O_NONBLOCK */