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)
}
}
defer ln.Close()
var server Conn
- errc := make(chan error)
+ errc := make(chan error, 1)
go func() {
var err error
server, err = ln.Accept()
t.Fatal(err)
}
defer server.Close()
+
var buf [128]byte
allocs := testing.AllocsPerRun(1000, func() {
_, err := server.Write(buf[:])
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) {
// 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
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
// 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
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