mirror of
https://github.com/golang/go
synced 2024-11-25 12:47:56 -07:00
net: rearrange the call order of runtime-integrated network pollster and syscall functions
This CL rearranges the call order for raw networking primitives like the following; - For dialers that open active connections, pollDesc.Init will be called before syscall.Connect. - For stream listeners that open passive stream connections, pollDesc.Init will be called just after syscall.Listen. - For datagram listeners that open datagram connections, pollDesc.Init will be called just after syscall.Bind. This is in preparation for runtime-integrated network pollster for BSD variants. Update #5199 R=golang-dev, alex.brainman CC=golang-dev https://golang.org/cl/12730043
This commit is contained in:
parent
a454d2fd2e
commit
5d5defc77f
@ -53,10 +53,6 @@ func socket(net string, f, t, p int, ipv6only bool, laddr, raddr sockaddr, deadl
|
|||||||
closesocket(s)
|
closesocket(s)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := fd.init(); err != nil {
|
|
||||||
fd.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function makes a network file descriptor for stream
|
// This function makes a network file descriptor for stream
|
||||||
// and datagram dialers, stream and datagram listeners.
|
// and datagram dialers, stream and datagram listeners.
|
||||||
@ -75,7 +71,7 @@ func socket(net string, f, t, p int, ipv6only bool, laddr, raddr sockaddr, deadl
|
|||||||
if laddr != nil && raddr == nil {
|
if laddr != nil && raddr == nil {
|
||||||
switch t {
|
switch t {
|
||||||
case syscall.SOCK_STREAM, syscall.SOCK_SEQPACKET:
|
case syscall.SOCK_STREAM, syscall.SOCK_SEQPACKET:
|
||||||
if err := fd.listenStream(laddr, toAddr); err != nil {
|
if err := fd.listenStream(laddr, listenerBacklog, toAddr); err != nil {
|
||||||
fd.Close()
|
fd.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -107,6 +103,9 @@ func (fd *netFD) dial(laddr, raddr sockaddr, deadline time.Time, toAddr func(sys
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := fd.init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
var rsa syscall.Sockaddr
|
var rsa syscall.Sockaddr
|
||||||
if raddr != nil {
|
if raddr != nil {
|
||||||
if rsa, err = raddr.sockaddr(fd.family); err != nil {
|
if rsa, err = raddr.sockaddr(fd.family); err != nil {
|
||||||
@ -133,7 +132,7 @@ func (fd *netFD) dial(laddr, raddr sockaddr, deadline time.Time, toAddr func(sys
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fd *netFD) listenStream(laddr sockaddr, toAddr func(syscall.Sockaddr) Addr) error {
|
func (fd *netFD) listenStream(laddr sockaddr, backlog int, toAddr func(syscall.Sockaddr) Addr) error {
|
||||||
if err := setDefaultListenerSockopts(fd.sysfd); err != nil {
|
if err := setDefaultListenerSockopts(fd.sysfd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -144,6 +143,12 @@ func (fd *netFD) listenStream(laddr sockaddr, toAddr func(syscall.Sockaddr) Addr
|
|||||||
return os.NewSyscallError("bind", err)
|
return os.NewSyscallError("bind", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := syscall.Listen(fd.sysfd, backlog); err != nil {
|
||||||
|
return os.NewSyscallError("listen", err)
|
||||||
|
}
|
||||||
|
if err := fd.init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
lsa, _ := syscall.Getsockname(fd.sysfd)
|
lsa, _ := syscall.Getsockname(fd.sysfd)
|
||||||
fd.setAddr(toAddr(lsa), nil)
|
fd.setAddr(toAddr(lsa), nil)
|
||||||
return nil
|
return nil
|
||||||
@ -180,6 +185,9 @@ func (fd *netFD) listenDatagram(laddr sockaddr, toAddr func(syscall.Sockaddr) Ad
|
|||||||
return os.NewSyscallError("bind", err)
|
return os.NewSyscallError("bind", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := fd.init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
lsa, _ := syscall.Getsockname(fd.sysfd)
|
lsa, _ := syscall.Getsockname(fd.sysfd)
|
||||||
fd.setAddr(toAddr(lsa), nil)
|
fd.setAddr(toAddr(lsa), nil)
|
||||||
return nil
|
return nil
|
||||||
|
@ -301,10 +301,5 @@ func ListenTCP(net string, laddr *TCPAddr) (*TCPListener, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = syscall.Listen(fd.sysfd, listenerBacklog)
|
|
||||||
if err != nil {
|
|
||||||
fd.Close()
|
|
||||||
return nil, &OpError{"listen", net, laddr, err}
|
|
||||||
}
|
|
||||||
return &TCPListener{fd}, nil
|
return &TCPListener{fd}, nil
|
||||||
}
|
}
|
||||||
|
@ -283,11 +283,6 @@ func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = syscall.Listen(fd.sysfd, listenerBacklog)
|
|
||||||
if err != nil {
|
|
||||||
fd.Close()
|
|
||||||
return nil, &OpError{Op: "listen", Net: net, Addr: laddr, Err: err}
|
|
||||||
}
|
|
||||||
return &UnixListener{fd, laddr.Name}, nil
|
return &UnixListener{fd, laddr.Name}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user