1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:46:58 -07:00

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
This commit is contained in:
Dmitriy Vyukov 2013-03-14 10:32:42 +04:00
parent ffbcd89f62
commit a11d7d4e11

View File

@ -86,21 +86,19 @@ func (fd *netFD) connect(ra syscall.Sockaddr) error {
if err := fd.pd.PrepareWrite(); err != nil {
return err
}
err := syscall.Connect(fd.sysfd, ra)
if err == syscall.EINPROGRESS {
for {
err := syscall.Connect(fd.sysfd, ra)
if err == nil || err == syscall.EISCONN {
break
}
if err != syscall.EINPROGRESS && err != syscall.EALREADY && err != syscall.EINTR {
return err
}
if err = fd.pd.WaitWrite(); err != nil {
return err
}
var e int
e, err = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR)
if err != nil {
return os.NewSyscallError("getsockopt", err)
}
if e != 0 {
err = syscall.Errno(e)
}
}
return err
return nil
}
// Add a reference to this fd.