From 35c986489795b7d5619fb14ec5077fd3c1758eb7 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Tue, 25 Mar 2025 10:42:10 +0100 Subject: [PATCH] internal/poll: always use SetFileCompletionNotificationModes on non-socket handles SetFileCompletionNotificationModes can be unconditionally called on non-socket handles. The Windows poll.FD implementation still doesn't support non-socket pollable handles yet, so this CL doesn't change any behavior. Support for pollable non-socket handles will come in subsequent CLs. For #19098. Change-Id: I811a61497cfbb26acb566c20367d212335b9d551 Reviewed-on: https://go-review.googlesource.com/c/go/+/660495 Reviewed-by: Damien Neil LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Auto-Submit: Damien Neil --- src/internal/poll/fd_windows.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index 5eefeb90f1..958edfbc0c 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -27,7 +27,7 @@ var ( // SetFileCompletionNotificationModes crashes on some systems (see // https://support.microsoft.com/kb/2568167 for details). -var useSetFileCompletionNotificationModes bool // determines is SetFileCompletionNotificationModes is present and safe to use +var socketCanUseSetFileCompletionNotificationModes bool // determines is SetFileCompletionNotificationModes is present and sockets can safely use it // checkSetFileCompletionNotificationModes verifies that // SetFileCompletionNotificationModes Windows API is present @@ -50,7 +50,7 @@ func checkSetFileCompletionNotificationModes() { return } } - useSetFileCompletionNotificationModes = true + socketCanUseSetFileCompletionNotificationModes = true } // InitWSA initiates the use of the Winsock DLL by the current process. @@ -324,16 +324,12 @@ func (fd *FD) Init(net string, pollable bool) (string, error) { if err != nil { return "", err } - if pollable && useSetFileCompletionNotificationModes { - // We do not use events, so we can skip them always. - flags := uint8(syscall.FILE_SKIP_SET_EVENT_ON_HANDLE) - switch net { - case "tcp", "tcp4", "tcp6", - "udp", "udp4", "udp6": - flags |= syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS - } - err := syscall.SetFileCompletionNotificationModes(fd.Sysfd, flags) - if err == nil && flags&syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS != 0 { + if pollable && (fd.kind != kindNet || socketCanUseSetFileCompletionNotificationModes) { + // Non-socket handles can use SetFileCompletionNotificationModes without problems. + err := syscall.SetFileCompletionNotificationModes(fd.Sysfd, + syscall.FILE_SKIP_SET_EVENT_ON_HANDLE|syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS, + ) + if err == nil { fd.skipSyncNotif = true } } -- 2.51.0