From: Patrik Wall Date: Thu, 30 Apr 2026 12:43:49 +0000 (+0200) Subject: Events: support for SO_SNDBUF on outbound peer connections X-Git-Tag: release-1.31.3~13 X-Git-Url: http://git.kaiwu.me/http/$%7BGITURL%7D/doc/static/gitweb.js?a=commitdiff_plain;h=3fe9fc45735b059ab6d3ee997e06bcc6850b36ab;p=nginx.git Events: support for SO_SNDBUF on outbound peer connections ngx_event_connect_peer() honors SO_RCVBUF via pc->rcvbuf but had no equivalent for SO_SNDBUF. This adds pc->sndbuf and the matching setsockopt() call, mirroring the existing SO_RCVBUF path. Both setsockopt() calls are made non-fatal. Existing callers leaving sndbuf at 0 retain prior behavior, since setsockopt() is only invoked when the field is non-zero. These fields are consumed by various proxying modules in follow-up commits. --- diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 668084a7b..e18b3a5c6 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -65,11 +65,23 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc) if (pc->rcvbuf) { if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, - (const void *) &pc->rcvbuf, sizeof(int)) == -1) + (const void *) &pc->rcvbuf, sizeof(int)) + == -1) { ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, - "setsockopt(SO_RCVBUF) failed"); - goto failed; + "setsockopt(SO_RCVBUF, %d) failed, ignored", + pc->rcvbuf); + } + } + + if (pc->sndbuf) { + if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, + (const void *) &pc->sndbuf, sizeof(int)) + == -1) + { + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, + "setsockopt(SO_SNDBUF, %d) failed, ignored", + pc->sndbuf); } } diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h index e428e7376..0604fef0f 100644 --- a/src/event/ngx_event_connect.h +++ b/src/event/ngx_event_connect.h @@ -57,6 +57,7 @@ struct ngx_peer_connection_s { int type; int rcvbuf; + int sndbuf; ngx_log_t *log;