1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

beam: replace SendPair() with the simpler SendConn()

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-03-31 11:58:29 -07:00
parent 5833e78887
commit 4f92ffb500
2 changed files with 12 additions and 12 deletions

View file

@ -36,10 +36,10 @@ func SendPipe(dst Sender, data []byte) (*os.File, error) {
return w, nil
}
func SendPair(dst Sender, data []byte) (in ReceiveCloser, out SendCloser, err error) {
func SendConn(dst Sender, data []byte) (conn *UnixConn, err error) {
local, remote, err := SocketPair()
if err != nil {
return nil, nil, err
return nil, err
}
defer func() {
if err != nil {
@ -47,22 +47,22 @@ func SendPair(dst Sender, data []byte) (in ReceiveCloser, out SendCloser, err er
remote.Close()
}
}()
endpoint, err := FileConn(local)
conn, err = FileConn(local)
if err != nil {
return nil, nil, err
return nil, err
}
local.Close()
if err := dst.Send(data, remote); err != nil {
return nil, nil, err
return nil, err
}
return ReceiveCloser(endpoint), SendCloser(endpoint), nil
return conn, nil
}
func ReceivePair(src Receiver) ([]byte, Receiver, Sender, error) {
func ReceiveConn(src Receiver) ([]byte, *UnixConn, error) {
for {
data, f, err := src.Receive()
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
if f == nil {
// Skip empty attachments
@ -74,10 +74,10 @@ func ReceivePair(src Receiver) ([]byte, Receiver, Sender, error) {
// (for example might be a regular file, directory etc)
continue
}
return data, Receiver(conn), Sender(conn), nil
return data, conn, nil
}
panic("impossibru!")
return nil, nil, nil, nil
return nil, nil, nil
}
func Copy(dst Sender, src Receiver) (int, error) {

View file

@ -17,13 +17,13 @@ import (
// not point to a connection, that message will be skipped.
//
func Listen(conn Sender, name string) (net.Listener, error) {
in, _, err := SendPair(conn, []byte(name))
endpoint, err := SendConn(conn, []byte(name))
if err != nil {
return nil, err
}
return &listener{
name: name,
endpoint: in,
endpoint: endpoint,
}, nil
}