]> Cypherpunks repositories - gostls13.git/commitdiff
net: Added function SetTimeout() to interface Listener.
authorAleksandar Dezelin <dezelin@gmail.com>
Tue, 16 Aug 2011 22:36:51 +0000 (18:36 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 16 Aug 2011 22:36:51 +0000 (18:36 -0400)
Fixes #2148.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4905042

src/pkg/net/fd.go
src/pkg/net/tcpsock.go
src/pkg/net/unixsock.go

index fd39d858c3540b34a31e1164ea5af9dd11b4c176..707dccaa421392ef7851cad76fe0d57c0e84cce9 100644 (file)
@@ -585,6 +585,11 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
 
        fd.incref()
        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.
        // 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.
                        return nil, os.EINVAL
                }
                s, rsa, e = syscall.Accept(fd.sysfd)
-               if e != syscall.EAGAIN {
+               if e != syscall.EAGAIN || fd.rdeadline < 0 {
                        break
                }
                syscall.ForkLock.RUnlock()
index 9ee6c14f7a3ebdc5a0cb644b9b77a3870fd18e1b..a118fced4e94a3927e0e5eea14e2643277f89ec3 100644 (file)
@@ -298,6 +298,14 @@ func (l *TCPListener) Close() os.Error {
 // Addr returns the listener's network address, a *TCPAddr.
 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.
 // It is the caller's responsibility to close f when finished.
 // Closing c does not affect f, and closing f does not affect c.
index 8c26a7bafd50a8ed4f52d42d64364987dbce0512..0bea867b18cfc09ee91adc1a287c05901af63c88 100644 (file)
@@ -423,6 +423,14 @@ func (l *UnixListener) Close() os.Error {
 // Addr returns the listener's network address.
 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.
 // It is the caller's responsibility to close f when finished.
 // Closing c does not affect f, and closing f does not affect c.