X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jbsockets.c;h=48f43c922b7819fb0ca428662be4b4929763b9fb;hp=13a6a0c2b7ded4d3f6eefd864a4958d9cf0c8813;hb=d2e582689e83de3a8511e5e85e15fa045a5cc666;hpb=8e025f46200aef5c4f6961b5aca59695d4ce6084 diff --git a/jbsockets.c b/jbsockets.c index 13a6a0c2..48f43c92 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.127 2014/06/03 10:27:56 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.134 2015/11/06 13:37:35 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -8,7 +8,7 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.127 2014/06/03 10:27:56 fabia * OS-independent. Contains #ifdefs to make this work * on many platforms. * - * Copyright : Written by and Copyright (C) 2001-2014 the + * Copyright : Written by and Copyright (C) 2001-2016 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -123,6 +123,33 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct client_state *csp); #endif +/********************************************************************* + * + * Function : set_no_delay_flag + * + * Description : Disables TCP coalescence for the given socket. + * + * Parameters : + * 1 : fd = The file descriptor to operate on + * + * Returns : void + * + *********************************************************************/ +static void set_no_delay_flag(int fd) +{ +#ifdef TCP_NODELAY + int mi = 1; + + if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &mi, sizeof(int))) + { + log_error(LOG_LEVEL_ERROR, + "Failed to disable TCP coalescence for socket %d", fd); + } +#else +#warning set_no_delay_flag() is a nop due to lack of TCP_NODELAY +#endif /* def TCP_NODELAY */ +} + /********************************************************************* * * Function : connect_to @@ -279,6 +306,7 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client "Server socket number too high to use select(): %d >= %d", fd, FD_SETSIZE); close_socket(fd); + freeaddrinfo(result); return JB_INVALID_SOCKET; } #endif @@ -287,12 +315,7 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client mark_socket_for_close_on_execute(fd); #endif -#ifdef TCP_NODELAY - { /* turn off TCP coalescence */ - int mi = 1; - setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &mi, sizeof (int)); - } -#endif /* def TCP_NODELAY */ + set_no_delay_flag(fd); #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) if ((flags = fcntl(fd, F_GETFL, 0)) != -1) @@ -480,12 +503,7 @@ static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct cli } #endif -#ifdef TCP_NODELAY - { /* turn off TCP coalescence */ - int mi = 1; - setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &mi, sizeof (int)); - } -#endif /* def TCP_NODELAY */ + set_no_delay_flag(fd); #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) if ((flags = fcntl(fd, F_GETFL, 0)) != -1) @@ -909,10 +927,6 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) fd = socket(AF_INET, SOCK_STREAM, 0); #endif /* def HAVE_RFC2553 */ -#ifdef FEATURE_EXTERNAL_FILTERS - mark_socket_for_close_on_execute(fd); -#endif - #ifdef _WIN32 if (fd == JB_INVALID_SOCKET) #else @@ -926,6 +940,10 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) #endif } +#ifdef FEATURE_EXTERNAL_FILTERS + mark_socket_for_close_on_execute(fd); +#endif + #ifndef _WIN32 /* * This is not needed for Win32 - in fact, it stops @@ -995,6 +1013,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) { if (errno != EINTR) { + close_socket(fd); return(-1); } } @@ -1288,7 +1307,7 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) 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))) + if (0 != setsockopt(afd, SOL_SOCKET, SO_LINGER, &linger_options, sizeof(linger_options))) { log_error(LOG_LEVEL_ERROR, "Setting SO_LINGER on socket %d failed.", afd); } @@ -1310,6 +1329,8 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) mark_socket_for_close_on_execute(afd); #endif + set_no_delay_flag(afd); + csp->cfd = afd; #ifdef HAVE_RFC2553 csp->ip_addr_str = malloc_or_die(NI_MAXHOST);