Commit d12a7d39 authored by Alexey Borzenkov's avatar Alexey Borzenkov Committed by Alex Brainman

net: use read deadline in Accept on windows

Fixes #4296.

R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/6815044
parent 8884fabf
......@@ -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.
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment