X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jbsockets.c;h=d650dba13dcfbdb950c8224efa30b712c0c2b4ca;hp=2e20a83fdf4b97dfe2705b5bbe68caa0020a5481;hb=4aad00d5930198d03667bf0cc205abc11fbfd52e;hpb=c076ee3df798ec00e61c1708d0b1e352971ee41c diff --git a/jbsockets.c b/jbsockets.c index 2e20a83f..d650dba1 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.114 2012/03/09 17:56:41 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.119 2012/10/23 10:17:36 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -83,7 +83,6 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.114 2012/03/09 17:56:41 fabia #endif -#ifdef FEATURE_CONNECTION_KEEP_ALIVE #ifdef HAVE_POLL #ifdef __GLIBC__ #include @@ -91,7 +90,6 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.114 2012/03/09 17:56:41 fabia #include #endif /* def __GLIBC__ */ #endif /* HAVE_POLL */ -#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ #include "project.h" @@ -728,13 +726,13 @@ void drain_and_close_socket(jb_socket fd) int bytes_drained; #ifdef HAVE_SHUTDOWN -/* Apparently Windows has shutdown() but now SHUT_WR */ +/* Apparently Windows has shutdown() but not SHUT_WR. */ #ifndef SHUT_WR #define SHUT_WR 1 #endif if (0 != shutdown(fd, SHUT_WR)) { - log_error(LOG_LEVEL_ERROR, "Failed to shutdown socket %d %E", fd); + log_error(LOG_LEVEL_CONNECT, "Failed to shutdown socket %d: %E", fd); } #endif #define ARBITRARY_DRAIN_LIMIT 10000 @@ -742,10 +740,19 @@ void drain_and_close_socket(jb_socket fd) { char drainage[500]; + if (!data_is_available(fd, 0)) + { + /* + * If there is no data available right now, don't try + * to drain the socket as read_socket() could block. + */ + break; + } + bytes_drained = read_socket(fd, drainage, sizeof(drainage)); if (bytes_drained < 0) { - log_error(LOG_LEVEL_ERROR, "Failed to drain socket %d %E", fd); + log_error(LOG_LEVEL_CONNECT, "Failed to drain socket %d: %E", fd); } else if (bytes_drained > 0) { @@ -1267,6 +1274,18 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) } #endif +#ifdef SO_LINGER + { + struct linger linger_options; + linger_options.l_onoff = 1; + linger_options.l_linger = 5; + if (0 != setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_options, sizeof(linger_options))) + { + log_error(LOG_LEVEL_ERROR, "Setting SO_LINGER on socket %d failed.", afd); + } + } +#endif + csp->cfd = afd; #ifdef HAVE_RFC2553 csp->ip_addr_str = malloc(NI_MAXHOST); @@ -1411,7 +1430,6 @@ unsigned long resolve_hostname_to_ip(const char *host) } -#ifdef FEATURE_CONNECTION_KEEP_ALIVE /********************************************************************* * * Function : socket_is_still_alive @@ -1465,7 +1483,6 @@ int socket_is_still_alive(jb_socket sfd) return (no_data_waiting || (1 == recv(sfd, buf, 1, MSG_PEEK))); } -#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ /*