X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jbsockets.c;h=d650dba13dcfbdb950c8224efa30b712c0c2b4ca;hp=7df26911c51be2332772f6c5deed370066441f70;hb=d7e8efb337c8dbe3dec53705d9a05a2a1153cc12;hpb=1e80929b9f530196a2582ecc1f1d0e89a7351c35 diff --git a/jbsockets.c b/jbsockets.c index 7df26911..d650dba1 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.116 2012/10/12 11:23:53 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.116 2012/10/12 11:23:53 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.116 2012/10/12 11:23:53 fabia #include #endif /* def __GLIBC__ */ #endif /* HAVE_POLL */ -#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ #include "project.h" @@ -742,6 +740,15 @@ 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) { @@ -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 */ /*