mirror of
https://github.com/golang/go
synced 2024-11-25 01:47:56 -07:00
net: actually reset deadline when time is zero
R=golang-dev, r CC=golang-dev https://golang.org/cl/5570056
This commit is contained in:
parent
0ae6084fef
commit
fe30ed2dcf
@ -117,12 +117,20 @@ func setWriteBuffer(fd *netFD, bytes int) error {
|
||||
}
|
||||
|
||||
func setReadDeadline(fd *netFD, t time.Time) error {
|
||||
if t.IsZero() {
|
||||
fd.rdeadline = 0
|
||||
} else {
|
||||
fd.rdeadline = t.UnixNano()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setWriteDeadline(fd *netFD, t time.Time) error {
|
||||
if t.IsZero() {
|
||||
fd.wdeadline = 0
|
||||
} else {
|
||||
fd.wdeadline = t.UnixNano()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -77,3 +77,30 @@ func TestTimeoutTCP(t *testing.T) {
|
||||
testTimeout(t, "tcp", addr, false)
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestDeadlineReset(t *testing.T) {
|
||||
if runtime.GOOS == "plan9" {
|
||||
return
|
||||
}
|
||||
ln, err := Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
tl := ln.(*TCPListener)
|
||||
tl.SetDeadline(time.Now().Add(1 * time.Minute))
|
||||
tl.SetDeadline(time.Time{}) // reset it
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := ln.Accept()
|
||||
errc <- err
|
||||
}()
|
||||
select {
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
// Pass.
|
||||
case err := <-errc:
|
||||
// Accept should never return; we never
|
||||
// connected to it.
|
||||
t.Errorf("unexpected return from Accept; err=%v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user