Beam: USocketPair returns a *net.UnixConn socket pair for convenience.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-03-18 17:11:03 -07:00
parent be03962d64
commit 968d5bb08f

View file

@ -152,6 +152,27 @@ func SocketPair() (*os.File, *os.File, error) {
return os.NewFile(uintptr(pair[0]), ""), os.NewFile(uintptr(pair[1]), ""), nil
}
func USocketPair() (*net.UnixConn, *net.UnixConn, error) {
a, b, err := SocketPair()
if err != nil {
return nil, nil, err
}
fmt.Printf("SocketPair() = %v, %v\n", a.Fd(), b.Fd())
uA, err := FdConn(int(a.Fd()))
if err != nil {
a.Close()
b.Close()
return nil, nil, err
}
uB, err := FdConn(int(b.Fd()))
if err != nil {
a.Close()
b.Close()
return nil, nil, err
}
return uA, uB, nil
}
// FdConn wraps a file descriptor in a standard *net.UnixConn object, or
// returns an error if the file descriptor does not point to a unix socket.
func FdConn(fd int) (*net.UnixConn, error) {