From 968d5bb08f3254642d5a59a831f3418fbd43c521 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 18 Mar 2014 17:11:03 -0700 Subject: [PATCH] Beam: USocketPair returns a *net.UnixConn socket pair for convenience. Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- beam/unix.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/beam/unix.go b/beam/unix.go index 7f7a73b..85b3806 100644 --- a/beam/unix.go +++ b/beam/unix.go @@ -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) {