]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: avoid convT2I allocs for ERROR_IO_PENDING instead of WSAEINPROGRESS
authorAlex Brainman <alex.brainman@gmail.com>
Sat, 10 Sep 2016 04:04:46 +0000 (14:04 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Sun, 11 Sep 2016 01:42:30 +0000 (01:42 +0000)
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 <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/tcpsock_test.go
src/syscall/mksyscall_windows.go
src/syscall/zsyscall_windows.go

index 4af47fcf1a68f53f233f8d0fe80e851ebaf0b872..d80a3736bfb437f0cd62cd893386f3be2b0a8d68 100644 (file)
@@ -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) {
index a39f3c36356c2d301ae74c11c6096e30c08addf9..fcc847616cdfb3a15b571d50f5fb38977695c1c6 100644 (file)
@@ -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
index 7e235526257e128196772e385b2d2b38a6285111..c99e3cf532063807d51754de3b833e1aedd0d0ea 100644 (file)
@@ -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