]> git.kaiwu.me - nginx.git/commitdiff
Events: support for SO_SNDBUF on outbound peer connections
authorPatrik Wall <patrik.wall.91@gmail.com>
Thu, 30 Apr 2026 12:43:49 +0000 (14:43 +0200)
committerSergey Kandaurov <s.kandaurov@f5.com>
Wed, 15 Jul 2026 12:59:06 +0000 (16:59 +0400)
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.

src/event/ngx_event_connect.c
src/event/ngx_event_connect.h

index 668084a7bb919ece3406e34aea7d8a23734ebce0..e18b3a5c6ab6abf1ebd49b4ce45c0dbda9e0c477 100644 (file)
@@ -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);
         }
     }
 
index e428e73765b5c9969880999cfaed005eb95b0275..0604fef0f170df0593770319562a8a927a62b0bf 100644 (file)
@@ -57,6 +57,7 @@ struct ngx_peer_connection_s {
 
     int                              type;
     int                              rcvbuf;
+    int                              sndbuf;
 
     ngx_log_t                       *log;