]> Cypherpunks repositories - gostls13.git/commitdiff
net: optimize ctxDone usage
authorMikhail Faraponov <11322032+moredure@users.noreply.github.com>
Tue, 16 Nov 2021 19:41:43 +0000 (19:41 +0000)
committerDamien Neil <dneil@google.com>
Thu, 18 Nov 2021 19:16:38 +0000 (19:16 +0000)
Change-Id: I6db6fcf0ebe36da77af062114b5264405f15fee8
GitHub-Last-Rev: 80a97262bb220bb3958c94016eadf385cdf915e8
GitHub-Pull-Request: golang/go#49620
Reviewed-on: https://go-review.googlesource.com/c/go/+/364514
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>

src/net/fd_unix.go

index 4ded833bbf20232f1a1342cd3daa99e6090da12e..aaa7a1c18559b10808ad6f87bb5493145c5a5444 100644 (file)
@@ -95,7 +95,8 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc
        // The interrupter goroutine waits for the context to be done and
        // interrupts the dial (by altering the fd's write deadline, which
        // wakes up waitWrite).
-       if ctxDone := ctx.Done(); ctxDone != nil {
+       ctxDone := ctx.Done()
+       if ctxDone != nil {
                // Wait for the interrupter goroutine to exit before returning
                // from connect.
                done := make(chan struct{})
@@ -139,7 +140,7 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc
                // details.
                if err := fd.pfd.WaitWrite(); err != nil {
                        select {
-                       case <-ctx.Done():
+                       case <-ctxDone:
                                return nil, mapErr(ctx.Err())
                        default:
                        }