From: Artem Boldariev Date: Thu, 25 Aug 2022 18:59:23 +0000 (+0300) Subject: Extend isc__nm_socket_tcp_nodelay() to accept value X-Git-Tag: v9.19.9~68^2~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4606384345d299d0b910ac889549a228dcea27c7;p=thirdparty%2Fbind9.git Extend isc__nm_socket_tcp_nodelay() to accept value This makes it possible to both enable and disable Nagle's algorithm for a TCP socket descriptor, before the change it was possible only to disable it. --- diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index 962a5b4386c..c6f7eed961f 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -2434,7 +2434,7 @@ http_transpost_tcp_nodelay(isc_nmhandle_t *transphandle) { (void)uv_fileno((uv_handle_t *)&tcpsock->uv_handle.tcp, &tcp_fd); RUNTIME_CHECK(tcp_fd != (uv_os_fd_t)-1); - (void)isc__nm_socket_tcp_nodelay((uv_os_sock_t)tcp_fd); + (void)isc__nm_socket_tcp_nodelay((uv_os_sock_t)tcp_fd, true); } static isc_result_t diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 807bd151a88..1c229d314ab 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -1861,9 +1861,10 @@ isc__nm_socket_connectiontimeout(uv_os_sock_t fd, int timeout_ms); */ isc_result_t -isc__nm_socket_tcp_nodelay(uv_os_sock_t fd); +isc__nm_socket_tcp_nodelay(const uv_os_sock_t fd, bool value); /*%< - * Disables Nagle's algorithm on a TCP socket (sets TCP_NODELAY). + * Disables/Enables Nagle's algorithm on a TCP socket (sets TCP_NODELAY if + * 'value' equals 'true' or vice versa). */ isc_result_t diff --git a/lib/isc/netmgr/socket.c b/lib/isc/netmgr/socket.c index b2dce27805e..fc9b3ce880a 100644 --- a/lib/isc/netmgr/socket.c +++ b/lib/isc/netmgr/socket.c @@ -327,9 +327,17 @@ isc__nm_socket_connectiontimeout(uv_os_sock_t fd, int timeout_ms) { } isc_result_t -isc__nm_socket_tcp_nodelay(uv_os_sock_t fd) { +isc__nm_socket_tcp_nodelay(uv_os_sock_t fd, bool value) { #ifdef TCP_NODELAY - if (setsockopt_on(fd, IPPROTO_TCP, TCP_NODELAY) == -1) { + int ret; + + if (value) { + ret = setsockopt_on(fd, IPPROTO_TCP, TCP_NODELAY); + } else { + ret = setsockopt_off(fd, IPPROTO_TCP, TCP_NODELAY); + } + + if (ret == -1) { return (ISC_R_FAILURE); } else { return (ISC_R_SUCCESS);