mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: make {TCP,Unix}Listener implement syscall.Conn
This change adds the syscall.Conn interface to Listener types, with the caveat that only RawConn.Control is supported. Custom socket options can now be set safely. Updates #19435 Fixes #22065 Change-Id: I7e74780d00318dc54a923d1c628a18a36009acab Reviewed-on: https://go-review.googlesource.com/71651 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
ff4ee88162
commit
eed308de31
5 changed files with 143 additions and 0 deletions
|
|
@ -219,6 +219,18 @@ type UnixListener struct {
|
|||
|
||||
func (ln *UnixListener) ok() bool { return ln != nil && ln.fd != nil }
|
||||
|
||||
// SyscallConn returns a raw network connection.
|
||||
// This implements the syscall.Conn interface.
|
||||
//
|
||||
// The returned RawConn only supports calling Control. Read and
|
||||
// Write return an error.
|
||||
func (l *UnixListener) SyscallConn() (syscall.RawConn, error) {
|
||||
if !l.ok() {
|
||||
return nil, syscall.EINVAL
|
||||
}
|
||||
return newRawListener(l.fd)
|
||||
}
|
||||
|
||||
// AcceptUnix accepts the next incoming call and returns the new
|
||||
// connection.
|
||||
func (l *UnixListener) AcceptUnix() (*UnixConn, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue