From 77094923d744423500ec5d7d3c61195c9ae0582e Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 6 Nov 2015 13:34:56 +0000 Subject: [PATCH] Factor out set_no_delay_flag() to reduce code duplication While at it, log an error message if setting the flag fails and let the compiler emit a warning if Privoxy is compiled on a platform where the function is a nop. --- jbsockets.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/jbsockets.c b/jbsockets.c index 25b95a84..ff1d7a81 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.130 2014/10/18 11:28:05 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.131 2014/11/14 10:40:24 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -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 @@ -288,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) @@ -481,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) -- 2.39.2