]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: simplify IOCP association checks
authorqmuntal <quimmuntal@gmail.com>
Thu, 5 Feb 2026 13:57:53 +0000 (14:57 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Thu, 12 Feb 2026 04:16:35 +0000 (20:16 -0800)
This is a step towards deferring adding the handle to IOCP until the
first IO operation.

FD.pollable() obscures the fact that it is really checking if the handle
is associated with the IOCP. This doesn't need to be a function that
checks multiple conditions. It can be a simple boolean field that tracks
whether the handle is associated with the IOCP or not.

For #76391

Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race
Change-Id: I3ee6532f8a387fb5cfae8ae3d20ea9569f585e71
Reviewed-on: https://go-review.googlesource.com/c/go/+/742282
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/internal/poll/fd_windows.go

index c9e74d0699dde15ce6153d4c51eea56374a76a3f..6875557c6f2f21af129100b4c0d0bb377c3d3bf5 100644 (file)
@@ -269,7 +269,7 @@ func (fd *FD) execIO(mode int, submit func(o *operation) (uint32, error), buf []
                                }
                        }()
                }
-               if !fd.pollable() {
+               if !fd.associated {
                        // If the handle is opened for overlapped IO but we can't
                        // use the runtime poller, then we need to use an
                        // event to wait for the IO to complete.
@@ -370,7 +370,8 @@ type FD struct {
        // Whether FILE_FLAG_OVERLAPPED was not set when opening the file.
        isBlocking bool
 
-       disassociated bool
+       // Whether the handle is currently associated with the IOCP.
+       associated bool
 
        // readPinner and writePinner are automatically unpinned
        // before execIO returns.
@@ -400,12 +401,6 @@ func (fd *FD) addOffset(off int) {
        fd.offset += int64(off)
 }
 
-// pollable should be used instead of fd.pd.pollable(),
-// as it is aware of the disassociated state.
-func (fd *FD) pollable() bool {
-       return fd.pd.pollable() && !fd.disassociated
-}
-
 // fileKind describes the kind of file.
 type fileKind byte
 
@@ -458,6 +453,7 @@ func (fd *FD) Init(net string, pollable bool) error {
        if err != nil {
                return err
        }
+       fd.associated = true
 
        // FILE_SKIP_SET_EVENT_ON_HANDLE is always safe to use. We don't use that feature
        // and it adds some overhead to the Windows I/O manager.
@@ -490,7 +486,7 @@ func (fd *FD) DisassociateIOCP() error {
        }
        defer fd.readWriteUnlock()
 
-       if fd.isBlocking || !fd.pollable() {
+       if !fd.associated {
                // Nothing to disassociate.
                return nil
        }
@@ -500,7 +496,7 @@ func (fd *FD) DisassociateIOCP() error {
                return err
        }
        // tryReadWriteLock means we have exclusive access to fd.
-       fd.disassociated = true
+       fd.associated = false
        // Don't call fd.pd.close(), it would be too racy.
        // There is no harm on leaving fd.pd open until Close is called.
        return nil