+ socklen_t optlen = sizeof(socket_error);
+ if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, &socket_error, &optlen))
+ {
+ if (!socket_error)
+ {
+ /* Connection established, no need to try other addresses. */
+ break;
+ }
+ if (rp->ai_next != NULL)
+ {
+ /*
+ * There's another address we can try, so log that this
+ * one didn't work out. If the last one fails, too,
+ * it will get logged outside the loop body so we don't
+ * have to mention it here.
+ */
+ log_error(LOG_LEVEL_CONNECT, "Could not connect to [%s]:%s: %s.",
+ csp->http->host_ip_addr_str, service, strerror(socket_error));
+ }
+ }
+ else
+ {
+ socket_error = errno;
+ log_error(LOG_LEVEL_ERROR, "Could not get the state of "
+ "the connection to [%s]:%s: %s; dropping connection.",
+ csp->http->host_ip_addr_str, service, strerror(errno));
+ }