Beam: change the prototype of SendPipe() to return a *net.UnixSocket

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:06:31 -07:00
parent 188c2ef806
commit b637e5f04a
2 changed files with 14 additions and 9 deletions

View File

@ -17,11 +17,7 @@ import (
// not point to a connection, that message will be skipped. // not point to a connection, that message will be skipped.
// //
func Listen(conn *net.UnixConn, name string) (net.Listener, error) { func Listen(conn *net.UnixConn, name string) (net.Listener, error) {
fEndpoint, err := SendPipe(conn, []byte(name)) endpoint, err := SendPipe(conn, []byte(name))
if err != nil {
return nil, err
}
endpoint, err := FdConn(int(fEndpoint.Fd()))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -78,16 +78,25 @@ func Receive(conn *net.UnixConn) ([]byte, *os.File, error) {
// allows for arbitrarily complex service discovery and retry logic to take place, // allows for arbitrarily complex service discovery and retry logic to take place,
// without complicating application code. // without complicating application code.
// //
func SendPipe(conn *net.UnixConn, data []byte) (*os.File, error) { func SendPipe(conn *net.UnixConn, data []byte) (endpoint *net.UnixConn, err error) {
local, remote, err := SocketPair() local, remote, err := SocketPair()
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := Send(conn, data, remote); err != nil { defer func() {
remote.Close() if err != nil {
local.Close()
remote.Close()
}
}()
endpoint, err = FdConn(int(local.Fd()))
if err != nil {
return nil, err return nil, err
} }
return local, nil if err := Send(conn, data, remote); err != nil {
return nil, err
}
return endpoint, nil
} }
func receiveUnix(conn *net.UnixConn) ([]byte, []int, error) { func receiveUnix(conn *net.UnixConn) ([]byte, []int, error) {