Commit d72c96df authored by Aleksandar Dezelin's avatar Aleksandar Dezelin Committed by Russ Cox

net: Added function SetTimeout() to interface Listener.

Fixes #2148.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4905042
parent 182cf988
...@@ -585,6 +585,11 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. ...@@ -585,6 +585,11 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
fd.incref() fd.incref()
defer fd.decref() defer fd.decref()
if fd.rdeadline_delta > 0 {
fd.rdeadline = pollserver.Now() + fd.rdeadline_delta
} else {
fd.rdeadline = 0
}
// See ../syscall/exec.go for description of ForkLock. // See ../syscall/exec.go for description of ForkLock.
// It is okay to hold the lock across syscall.Accept // It is okay to hold the lock across syscall.Accept
...@@ -598,7 +603,7 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. ...@@ -598,7 +603,7 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
return nil, os.EINVAL return nil, os.EINVAL
} }
s, rsa, e = syscall.Accept(fd.sysfd) s, rsa, e = syscall.Accept(fd.sysfd)
if e != syscall.EAGAIN { if e != syscall.EAGAIN || fd.rdeadline < 0 {
break break
} }
syscall.ForkLock.RUnlock() syscall.ForkLock.RUnlock()
......
...@@ -298,6 +298,14 @@ func (l *TCPListener) Close() os.Error { ...@@ -298,6 +298,14 @@ func (l *TCPListener) Close() os.Error {
// Addr returns the listener's network address, a *TCPAddr. // Addr returns the listener's network address, a *TCPAddr.
func (l *TCPListener) Addr() Addr { return l.fd.laddr } func (l *TCPListener) Addr() Addr { return l.fd.laddr }
// SetTimeout sets the deadline associated with the listener
func (l *TCPListener) SetTimeout(nsec int64) os.Error {
if l == nil || l.fd == nil {
return os.EINVAL
}
return setTimeout(l.fd, nsec)
}
// File returns a copy of the underlying os.File, set to blocking mode. // File returns a copy of the underlying os.File, set to blocking mode.
// It is the caller's responsibility to close f when finished. // It is the caller's responsibility to close f when finished.
// Closing c does not affect f, and closing f does not affect c. // Closing c does not affect f, and closing f does not affect c.
......
...@@ -423,6 +423,14 @@ func (l *UnixListener) Close() os.Error { ...@@ -423,6 +423,14 @@ func (l *UnixListener) Close() os.Error {
// Addr returns the listener's network address. // Addr returns the listener's network address.
func (l *UnixListener) Addr() Addr { return l.fd.laddr } func (l *UnixListener) Addr() Addr { return l.fd.laddr }
// SetTimeout sets the deadline associated wuth the listener
func (l *UnixListener) SetTimeout(nsec int64) (err os.Error) {
if l == nil || l.fd == nil {
return os.EINVAL
}
return setTimeout(l.fd, nsec)
}
// File returns a copy of the underlying os.File, set to blocking mode. // File returns a copy of the underlying os.File, set to blocking mode.
// It is the caller's responsibility to close f when finished. // It is the caller's responsibility to close f when finished.
// Closing c does not affect f, and closing f does not affect c. // Closing c does not affect f, and closing f does not affect c.
......
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