beam: improve the API with Sender/Receiver interfaces and utilities: Copy/SendPipe/SendPair
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
071e5e5a65
commit
9c5fdb249f
5 changed files with 207 additions and 176 deletions
|
@ -16,18 +16,18 @@ import (
|
|||
// Note that if the underlying file descriptor received in attachment is nil or does
|
||||
// not point to a connection, that message will be skipped.
|
||||
//
|
||||
func Listen(conn *net.UnixConn, name string) (net.Listener, error) {
|
||||
endpoint, err := SendPipe(conn, []byte(name))
|
||||
func Listen(conn Sender, name string) (net.Listener, error) {
|
||||
in, _, err := SendPair(conn, []byte(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &listener{
|
||||
name: name,
|
||||
endpoint: endpoint,
|
||||
endpoint: in,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Connect(ctx *net.UnixConn, name string) (net.Conn, error) {
|
||||
func Connect(ctx *UnixConn, name string) (net.Conn, error) {
|
||||
l, err := Listen(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -41,12 +41,12 @@ func Connect(ctx *net.UnixConn, name string) (net.Conn, error) {
|
|||
|
||||
type listener struct {
|
||||
name string
|
||||
endpoint *net.UnixConn
|
||||
endpoint ReceiveCloser
|
||||
}
|
||||
|
||||
func (l *listener) Accept() (net.Conn, error) {
|
||||
for {
|
||||
_, f, err := Receive(l.endpoint)
|
||||
_, f, err := l.endpoint.Receive()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue