1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:54:39 -07:00

net: return correct local address for an accepted TCP connection

Fixes #2127.

R=rsc
CC=golang-dev
https://golang.org/cl/4873043
This commit is contained in:
Mikio Hara 2011-08-16 16:53:09 -04:00 committed by Russ Cox
parent a2677cf363
commit c20ced956e

View File

@ -591,13 +591,13 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
// because we have put fd.sysfd into non-blocking mode. // because we have put fd.sysfd into non-blocking mode.
syscall.ForkLock.RLock() syscall.ForkLock.RLock()
var s, e int var s, e int
var sa syscall.Sockaddr var rsa syscall.Sockaddr
for { for {
if fd.closing { if fd.closing {
syscall.ForkLock.RUnlock() syscall.ForkLock.RUnlock()
return nil, os.EINVAL return nil, os.EINVAL
} }
s, sa, e = syscall.Accept(fd.sysfd) s, rsa, e = syscall.Accept(fd.sysfd)
if e != syscall.EAGAIN { if e != syscall.EAGAIN {
break break
} }
@ -616,7 +616,8 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
syscall.Close(s) syscall.Close(s)
return nil, err return nil, err
} }
nfd.setAddr(fd.laddr, toAddr(sa)) lsa, _ := syscall.Getsockname(nfd.sysfd)
nfd.setAddr(toAddr(lsa), toAddr(rsa))
return nfd, nil return nfd, nil
} }