From: Michael Fraenkel Date: Thu, 19 Apr 2018 21:54:29 +0000 (-0400) Subject: net: calling File leaves the socket in nonblocking mode X-Git-Tag: go1.11beta1~752 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=60e3ebb9cba900f7b2f559b472726cee47e823c0;p=gostls13.git net: calling File leaves the socket in nonblocking mode On Unix systems, the underlying socket is no longer forced into blocking mode. Fixes #24942 Change-Id: I3e0c503c72df0844e30a63af298691dedacd1f46 Reviewed-on: https://go-review.googlesource.com/108297 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/net/fd_unix.go b/src/net/fd_unix.go index efe2e184af..145933e737 100644 --- a/src/net/fd_unix.go +++ b/src/net/fd_unix.go @@ -309,13 +309,5 @@ func (fd *netFD) dup() (f *os.File, err error) { return nil, err } - // We want blocking mode for the new fd, hence the double negative. - // This also puts the old fd into blocking mode, meaning that - // I/O will block the thread instead of letting us use the epoll server. - // Everything will still work, just with more threads. - if err = fd.pfd.SetBlocking(); err != nil { - return nil, os.NewSyscallError("setnonblock", err) - } - return os.NewFile(uintptr(ns), fd.name()), nil } diff --git a/src/net/net.go b/src/net/net.go index 5182c0de95..b023d7c93f 100644 --- a/src/net/net.go +++ b/src/net/net.go @@ -281,15 +281,13 @@ func (c *conn) SetWriteBuffer(bytes int) error { return nil } -// File sets the underlying os.File to blocking mode and returns a copy. +// File returns a copy of the underlying os.File // It is the caller's responsibility to close f when finished. // Closing c does not affect f, and closing f does not affect c. // // The returned os.File's file descriptor is different from the connection's. // Attempting to change properties of the original using this duplicate // may or may not have the desired effect. -// -// On Unix systems this will cause the SetDeadline methods to stop working. func (c *conn) File() (f *os.File, err error) { f, err = c.fd.dup() if err != nil { diff --git a/src/net/tcpsock.go b/src/net/tcpsock.go index 9528140b94..0421ce5674 100644 --- a/src/net/tcpsock.go +++ b/src/net/tcpsock.go @@ -292,8 +292,8 @@ func (l *TCPListener) SetDeadline(t time.Time) error { return nil } -// File returns a copy of the underlying os.File, set to blocking -// mode. It is the caller's responsibility to close f when finished. +// File returns a copy of the underlying os.File. +// It is the caller's responsibility to close f when finished. // Closing l does not affect f, and closing f does not affect l. // // The returned os.File's file descriptor is different from the diff --git a/src/net/unixsock.go b/src/net/unixsock.go index 20326dabea..551280f936 100644 --- a/src/net/unixsock.go +++ b/src/net/unixsock.go @@ -286,8 +286,8 @@ func (l *UnixListener) SetDeadline(t time.Time) error { return nil } -// File returns a copy of the underlying os.File, set to blocking -// mode. It is the caller's responsibility to close f when finished. +// File returns a copy of the underlying os.File. +// It is the caller's responsibility to close f when finished. // Closing l does not affect f, and closing f does not affect l. // // The returned os.File's file descriptor is different from the