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:
parent
0a187f629a
commit
95b759ad16
2 changed files with 14 additions and 9 deletions
|
@ -17,11 +17,7 @@ import (
|
|||
// not point to a connection, that message will be skipped.
|
||||
//
|
||||
func Listen(conn *net.UnixConn, name string) (net.Listener, error) {
|
||||
fEndpoint, err := SendPipe(conn, []byte(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoint, err := FdConn(int(fEndpoint.Fd()))
|
||||
endpoint, err := SendPipe(conn, []byte(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
15
beam/unix.go
15
beam/unix.go
|
@ -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,
|
||||
// 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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := Send(conn, data, remote); err != nil {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
local.Close()
|
||||
remote.Close()
|
||||
}
|
||||
}()
|
||||
endpoint, err = FdConn(int(local.Fd()))
|
||||
if err != nil {
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue