1
0
mirror of https://github.com/golang/go synced 2024-11-25 01:27: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:
Brad Fitzpatrick 2012-01-24 14:06:12 -08:00
parent 0ae6084fef
commit fe30ed2dcf
2 changed files with 37 additions and 2 deletions

View File

@ -117,12 +117,20 @@ func setWriteBuffer(fd *netFD, bytes int) error {
} }
func setReadDeadline(fd *netFD, t time.Time) error { func setReadDeadline(fd *netFD, t time.Time) error {
fd.rdeadline = t.UnixNano() if t.IsZero() {
fd.rdeadline = 0
} else {
fd.rdeadline = t.UnixNano()
}
return nil return nil
} }
func setWriteDeadline(fd *netFD, t time.Time) error { func setWriteDeadline(fd *netFD, t time.Time) error {
fd.wdeadline = t.UnixNano() if t.IsZero() {
fd.wdeadline = 0
} else {
fd.wdeadline = t.UnixNano()
}
return nil return nil
} }

View File

@ -77,3 +77,30 @@ func TestTimeoutTCP(t *testing.T) {
testTimeout(t, "tcp", addr, false) testTimeout(t, "tcp", addr, false)
<-done <-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)
}
}