Commit a11d7d4e authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

net: prepare connect() for new network poller

The problem is that new network poller can have spurious
rediness notifications. This implementation ensures that
the socket is actually connected.

R=golang-dev, rsc, akumar
CC=golang-dev
https://golang.org/cl/7785043
parent ffbcd89f
...@@ -86,21 +86,19 @@ func (fd *netFD) connect(ra syscall.Sockaddr) error { ...@@ -86,21 +86,19 @@ func (fd *netFD) connect(ra syscall.Sockaddr) error {
if err := fd.pd.PrepareWrite(); err != nil { if err := fd.pd.PrepareWrite(); err != nil {
return err return err
} }
err := syscall.Connect(fd.sysfd, ra) for {
if err == syscall.EINPROGRESS { err := syscall.Connect(fd.sysfd, ra)
if err = fd.pd.WaitWrite(); err != nil { if err == nil || err == syscall.EISCONN {
return err break
} }
var e int if err != syscall.EINPROGRESS && err != syscall.EALREADY && err != syscall.EINTR {
e, err = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR) return err
if err != nil {
return os.NewSyscallError("getsockopt", err)
} }
if e != 0 { if err = fd.pd.WaitWrite(); err != nil {
err = syscall.Errno(e) return err
} }
} }
return err return nil
} }
// Add a reference to this fd. // Add a reference to this fd.
......
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