]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: always use SetFileCompletionNotificationModes on non-socket handles
authorqmuntal <quimmuntal@gmail.com>
Tue, 25 Mar 2025 09:42:10 +0000 (10:42 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 25 Mar 2025 18:33:49 +0000 (11:33 -0700)
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 <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Damien Neil <dneil@google.com>

src/internal/poll/fd_windows.go

index 5eefeb90f193ee7ba54b070bccc80059956af678..958edfbc0cf641218f3d5fc4b237a9537a388e2f 100644 (file)
@@ -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
                }
        }