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 <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>
This commit is contained in:
qmuntal 2025-03-25 10:42:10 +01:00 committed by Gopher Robot
parent 6bf95d40bb
commit 35c9864897

View 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
}
}