From fca3dd3718080563f4bc6c4c8b6fbe681a1602fa Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sat, 10 Sep 2016 14:04:46 +1000 Subject: [PATCH] syscall: avoid convT2I allocs for ERROR_IO_PENDING instead of WSAEINPROGRESS CL 28484 mistakenly assumed that WSARecv returns WSAEINPROGRESS when there is nothing to read. But the error is ERROR_IO_PENDING. Fix that mistake. I was about to write a test for it. But I have found TestTCPReadWriteAllocs in net package that does nearly what I need, but was conveniently disabled. So enable and extend the test. Fixes #16988 Change-Id: I55e5cf8998a9cf29e92b398d702280bdf7d6fc85 Reviewed-on: https://go-review.googlesource.com/28990 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/tcpsock_test.go | 29 +++++++++++++++++++++++++---- src/syscall/mksyscall_windows.go | 10 +++------- src/syscall/zsyscall_windows.go | 10 +++------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/net/tcpsock_test.go b/src/net/tcpsock_test.go index 4af47fcf1a..d80a3736bf 100644 --- a/src/net/tcpsock_test.go +++ b/src/net/tcpsock_test.go @@ -460,11 +460,9 @@ func TestTCPConcurrentAccept(t *testing.T) { func TestTCPReadWriteAllocs(t *testing.T) { switch runtime.GOOS { - case "nacl", "windows": + case "nacl": // NaCl needs to allocate pseudo file descriptor // stuff. See syscall/fd_nacl.go. - // Windows uses closures and channels for IO - // completion port-based netpoll. See fd_windows.go. t.Skipf("not supported on %s", runtime.GOOS) } @@ -474,7 +472,7 @@ func TestTCPReadWriteAllocs(t *testing.T) { } defer ln.Close() var server Conn - errc := make(chan error) + errc := make(chan error, 1) go func() { var err error server, err = ln.Accept() @@ -489,6 +487,7 @@ func TestTCPReadWriteAllocs(t *testing.T) { t.Fatal(err) } defer server.Close() + var buf [128]byte allocs := testing.AllocsPerRun(1000, func() { _, err := server.Write(buf[:]) @@ -503,6 +502,28 @@ func TestTCPReadWriteAllocs(t *testing.T) { if allocs > 0 { t.Fatalf("got %v; want 0", allocs) } + + var bufwrt [128]byte + ch := make(chan bool) + defer close(ch) + go func() { + for <-ch { + _, err := server.Write(bufwrt[:]) + errc <- err + } + }() + allocs = testing.AllocsPerRun(1000, func() { + ch <- true + if _, err = io.ReadFull(client, buf[:]); err != nil { + t.Fatal(err) + } + if err := <-errc; err != nil { + t.Fatal(err) + } + }) + if allocs > 0 { + t.Fatalf("got %v; want 0", allocs) + } } func TestTCPStress(t *testing.T) { diff --git a/src/syscall/mksyscall_windows.go b/src/syscall/mksyscall_windows.go index a39f3c3635..fcc847616c 100644 --- a/src/syscall/mksyscall_windows.go +++ b/src/syscall/mksyscall_windows.go @@ -831,12 +831,8 @@ var _ unsafe.Pointer // Do the interface allocations only once for common // Errno values. -const ( - errnoWSAEINPROGRESS = 10036 -) - var ( - errWSAEINPROGRESS error = {{syscalldot}}Errno(errnoWSAEINPROGRESS) + errERROR_IO_PENDING error = {{syscalldot}}Errno(ERROR_IO_PENDING) ) // errnoErr returns common boxed Errno values, to prevent @@ -845,8 +841,8 @@ func errnoErr(e {{syscalldot}}Errno) error { switch e { case 0: return nil - case errnoWSAEINPROGRESS: - return errWSAEINPROGRESS + case ERROR_IO_PENDING: + return errERROR_IO_PENDING } // TODO: add more here, after collecting data on the common // error values see on Windows. (perhaps when running diff --git a/src/syscall/zsyscall_windows.go b/src/syscall/zsyscall_windows.go index 7e23552625..c99e3cf532 100644 --- a/src/syscall/zsyscall_windows.go +++ b/src/syscall/zsyscall_windows.go @@ -11,12 +11,8 @@ var _ unsafe.Pointer // Do the interface allocations only once for common // Errno values. -const ( - errnoWSAEINPROGRESS = 10036 -) - var ( - errWSAEINPROGRESS error = Errno(errnoWSAEINPROGRESS) + errERROR_IO_PENDING error = Errno(ERROR_IO_PENDING) ) // errnoErr returns common boxed Errno values, to prevent @@ -25,8 +21,8 @@ func errnoErr(e Errno) error { switch e { case 0: return nil - case errnoWSAEINPROGRESS: - return errWSAEINPROGRESS + case ERROR_IO_PENDING: + return errERROR_IO_PENDING } // TODO: add more here, after collecting data on the common // error values see on Windows. (perhaps when running -- 2.48.1