case *TCPAddr:
return &TCPListener{fd}, nil
case *UnixAddr:
- return &UnixListener{fd, laddr.Name}, nil
+ return &UnixListener{fd: fd, path: laddr.Name, unlink: false}, nil
}
fd.Close()
return nil, syscall.EINVAL
// typically use variables of type Listener instead of assuming Unix
// domain sockets.
type UnixListener struct {
- fd *netFD
- path string
+ fd *netFD
+ path string
+ unlink bool
}
// ListenUnix announces on the Unix domain socket laddr and returns a
if err != nil {
return nil, &OpError{Op: "listen", Net: net, Source: nil, Addr: laddr.opAddr(), Err: err}
}
- return &UnixListener{fd: fd, path: fd.laddr.String()}, nil
+ return &UnixListener{fd: fd, path: fd.laddr.String(), unlink: true}, nil
}
// AcceptUnix accepts the next incoming call and returns the new
// is at least compatible with the auto-remove
// sequence in ListenUnix. It's only non-Go
// programs that can mess us up.
- if l.path[0] != '@' {
+ if l.path[0] != '@' && l.unlink {
syscall.Unlink(l.path)
}
err := l.fd.Close()