diff options
author | Russ Cox <rsc@golang.org> | 2016-10-20 17:14:47 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2016-10-29 18:23:59 +0000 |
commit | 03d641b990bf83b0553d723a2b8764af48de4e11 (patch) | |
tree | 50d31945a92ed88a6b5c92564dd4865eeb989abb /src/net/tcpsock_test.go | |
parent | 21a1fe4ddf77a49fee1d82d1891e66b1dce932bb (diff) | |
download | go-git-03d641b990bf83b0553d723a2b8764af48de4e11.tar.gz |
net: break up >1GB reads and writes on stream connections
Also fix behavior of Buffers.WriteTo when writev returns an error.
Fixes #16266.
Change-Id: Idc9503408ce2cb460663768fab86035cbab11aef
Reviewed-on: https://go-review.googlesource.com/31584
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/tcpsock_test.go')
-rw-r--r-- | src/net/tcpsock_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/net/tcpsock_test.go b/src/net/tcpsock_test.go index d80a3736bf..0d283dfa4f 100644 --- a/src/net/tcpsock_test.go +++ b/src/net/tcpsock_test.go @@ -5,6 +5,7 @@ package net import ( + "fmt" "internal/testenv" "io" "reflect" @@ -654,3 +655,58 @@ func TestTCPSelfConnect(t *testing.T) { } } } + +// Test that >32-bit reads work on 64-bit systems. +// On 32-bit systems this tests that maxint reads work. +func TestTCPBig(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + + for _, writev := range []bool{false, true} { + t.Run(fmt.Sprintf("writev=%v", writev), func(t *testing.T) { + ln, err := newLocalListener("tcp") + if err != nil { + t.Fatal(err) + } + defer ln.Close() + + x := int(1 << 30) + x = x*5 + 1<<20 // just over 5 GB on 64-bit, just over 1GB on 32-bit + done := make(chan int) + go func() { + defer close(done) + c, err := ln.Accept() + if err != nil { + t.Error(err) + return + } + buf := make([]byte, x) + var n int + if writev { + var n64 int64 + n64, err = (&Buffers{buf}).WriteTo(c) + n = int(n64) + } else { + n, err = c.Write(buf) + } + if n != len(buf) || err != nil { + t.Errorf("Write(buf) = %d, %v, want %d, nil", n, err, x) + } + c.Close() + }() + + c, err := Dial("tcp", ln.Addr().String()) + if err != nil { + t.Fatal(err) + } + buf := make([]byte, x) + n, err := io.ReadFull(c, buf) + if n != len(buf) || err != nil { + t.Errorf("Read(buf) = %d, %v, want %d, nil", n, err, x) + } + c.Close() + <-done + }) + } +} |