mirror of
https://github.com/golang/go
synced 2024-11-20 04:14:49 -07:00
net: use read deadline in Accept on windows
Fixes #4296. R=golang-dev, alex.brainman CC=golang-dev https://golang.org/cl/6815044
This commit is contained in:
parent
8884fabfd7
commit
d12a7d39d1
@ -544,7 +544,7 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (*netFD, error) {
|
||||
var o acceptOp
|
||||
o.Init(fd, 'r')
|
||||
o.newsock = s
|
||||
_, err = iosrv.ExecIO(&o, 0)
|
||||
_, err = iosrv.ExecIO(&o, fd.rdeadline)
|
||||
if err != nil {
|
||||
closesocket(s)
|
||||
return nil, err
|
||||
|
@ -119,3 +119,30 @@ func TestDeadlineReset(t *testing.T) {
|
||||
t.Errorf("unexpected return from Accept; err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeoutAccept(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
t.Logf("skipping test on %q", runtime.GOOS)
|
||||
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(100 * time.Millisecond))
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := ln.Accept()
|
||||
errc <- err
|
||||
}()
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
// Accept shouldn't block indefinitely
|
||||
t.Errorf("Accept didn't return in an expected time")
|
||||
case <-errc:
|
||||
// Pass.
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user