From 8eaa7935db8c8b901f4dbb7d224a347bb3c33d7f Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Sat, 2 Dec 2023 15:11:36 +0000 Subject: [PATCH] net: clarify maxListenerBacklog windows implementation The previous TODO comments were somewhat ambiguous. This aims to provide a clearer understanding of the behavior on Windows. Windows does not offer a way to peek at the current backlog length, this is explicitly stated in the winapi for `listen`. When set to `syscall.SOMAXCONN`, the OS dynamically adjusts the backlog to a maximum reasonable value. It goes as far as the dotnet runtime itself introducing a new version of `listen` that does not accept a backlog parameter to help eliminate the confusion when comparing the behavior with UNIXes. The docs also mention that `SOMAXCONN_HINT(N)` can be used, and that it clips the final computed value between (200, 65535), which suggests windows might use a `uint16` to back this number. Either way it does not matter since windows will adjust this value anyway, so I removed the wrapping TODO as well. See https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen Change-Id: I7b2e7cb547467c4bfc572ef0477a58de8c772521 GitHub-Last-Rev: 34e74abffe8792c8709c73db4d7a5fa05f64b1d0 GitHub-Pull-Request: golang/go#63549 Reviewed-on: https://go-review.googlesource.com/c/go/+/535475 Reviewed-by: Damien Neil Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- src/net/sock_windows.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/net/sock_windows.go b/src/net/sock_windows.go index 5540135a2c..a519909bb0 100644 --- a/src/net/sock_windows.go +++ b/src/net/sock_windows.go @@ -11,8 +11,9 @@ import ( ) func maxListenerBacklog() int { - // TODO: Implement this - // NOTE: Never return a number bigger than 1<<16 - 1. See issue 5030. + // When the socket backlog is SOMAXCONN, Windows will set the backlog to + // "a reasonable maximum value". + // See: https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen return syscall.SOMAXCONN } -- 2.48.1