net: implement non-blocking connect

Refactored bind/connect from sock.go into netFD.connect(), as
a consequence newFD() doesn't accept laddr/raddr anymore, and
expects an (optional) call to netFD.connect() followed by a
call to netFD.setAddr().
Windows code is updated, but still uses blocking connect,
since otherwise it needs support for ConnectEx syscall.

R=brainman, rsc
CC=golang-dev
https://golang.org/cl/4303060
This commit is contained in:
Alexey Borzenkov 2011-03-28 23:40:01 -04:00 committed by Russ Cox
parent 98828f033a
commit 2f45f72dce
4 changed files with 83 additions and 41 deletions

View file

@ -9,7 +9,7 @@ import (
"syscall"
)
func newFileFD(f *os.File) (*netFD, os.Error) {
func newFileFD(f *os.File) (nfd *netFD, err os.Error) {
fd, errno := syscall.Dup(f.Fd())
if errno != 0 {
return nil, os.NewSyscallError("dup", errno)
@ -50,7 +50,11 @@ func newFileFD(f *os.File) (*netFD, os.Error) {
sa, _ = syscall.Getpeername(fd)
raddr := toAddr(sa)
return newFD(fd, 0, proto, laddr.Network(), laddr, raddr)
if nfd, err = newFD(fd, 0, proto, laddr.Network()); err != nil {
return nil, err
}
nfd.setAddr(laddr, raddr)
return nfd, nil
}
// FileConn returns a copy of the network connection corresponding to