From: Michael Sweet Date: Tue, 20 Sep 2016 19:23:40 +0000 (-0400) Subject: Handle partial failures when connecting (Issue #4866) X-Git-Tag: v2.2.1~9^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ca77b3e89dc1f75c91e1a084dba861e378c6c8d;p=thirdparty%2Fcups.git Handle partial failures when connecting (Issue #4866) --- diff --git a/CHANGES.txt b/CHANGES.txt index 943dca62e2..ac92a79929 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 6e2ad81966..e9ef53ea43 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -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 */