net: fix netFD.Close races

Fixes #271.
Fixes #321.

R=rsc, agl, cw
CC=golang-dev
https://golang.org/cl/163052
This commit is contained in:
Devon H. O'Dell 2009-12-01 23:28:57 -08:00 committed by Russ Cox
parent ff3ea68e52
commit eb16346dac
5 changed files with 98 additions and 75 deletions

View file

@ -332,9 +332,9 @@ func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error) {
}
return nil, e;
}
e1 := syscall.Listen(fd.fd, 8); // listenBacklog());
e1 := syscall.Listen(fd.sysfd, 8); // listenBacklog());
if e1 != 0 {
syscall.Close(fd.fd);
syscall.Close(fd.sysfd);
return nil, &OpError{"listen", "unix", laddr, os.Errno(e1)};
}
return &UnixListener{fd, laddr.Name}, nil;
@ -343,7 +343,7 @@ func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error) {
// AcceptUnix accepts the next incoming call and returns the new connection
// and the remote address.
func (l *UnixListener) AcceptUnix() (c *UnixConn, err os.Error) {
if l == nil || l.fd == nil || l.fd.fd < 0 {
if l == nil || l.fd == nil {
return nil, os.EINVAL
}
fd, e := l.fd.accept(sockaddrToUnix);