Skip to content

Commit 35c9864

Browse files
qmuntalgopherbot
authored andcommitted
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent 6bf95d4 commit 35c9864

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/internal/poll/fd_windows.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
// SetFileCompletionNotificationModes crashes on some systems (see
2828
// https://support.microsoft.com/kb/2568167 for details).
2929

30-
var useSetFileCompletionNotificationModes bool // determines is SetFileCompletionNotificationModes is present and safe to use
30+
var socketCanUseSetFileCompletionNotificationModes bool // determines is SetFileCompletionNotificationModes is present and sockets can safely use it
3131

3232
// checkSetFileCompletionNotificationModes verifies that
3333
// SetFileCompletionNotificationModes Windows API is present
@@ -50,7 +50,7 @@ func checkSetFileCompletionNotificationModes() {
5050
return
5151
}
5252
}
53-
useSetFileCompletionNotificationModes = true
53+
socketCanUseSetFileCompletionNotificationModes = true
5454
}
5555

5656
// 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) {
324324
if err != nil {
325325
return "", err
326326
}
327-
if pollable && useSetFileCompletionNotificationModes {
328-
// We do not use events, so we can skip them always.
329-
flags := uint8(syscall.FILE_SKIP_SET_EVENT_ON_HANDLE)
330-
switch net {
331-
case "tcp", "tcp4", "tcp6",
332-
"udp", "udp4", "udp6":
333-
flags |= syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
334-
}
335-
err := syscall.SetFileCompletionNotificationModes(fd.Sysfd, flags)
336-
if err == nil && flags&syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS != 0 {
327+
if pollable && (fd.kind != kindNet || socketCanUseSetFileCompletionNotificationModes) {
328+
// Non-socket handles can use SetFileCompletionNotificationModes without problems.
329+
err := syscall.SetFileCompletionNotificationModes(fd.Sysfd,
330+
syscall.FILE_SKIP_SET_EVENT_ON_HANDLE|syscall.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS,
331+
)
332+
if err == nil {
337333
fd.skipSyncNotif = true
338334
}
339335
}

0 commit comments

Comments
 (0)