Beam: allow sending messages without attachments.
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
c008283f8d
commit
0a187f629a
1 changed files with 10 additions and 5 deletions
15
beam/unix.go
15
beam/unix.go
|
@ -10,7 +10,11 @@ import (
|
||||||
// Send sends a new message on conn with data and f as payload and
|
// Send sends a new message on conn with data and f as payload and
|
||||||
// attachment, respectively.
|
// attachment, respectively.
|
||||||
func Send(conn *net.UnixConn, data []byte, f *os.File) error {
|
func Send(conn *net.UnixConn, data []byte, f *os.File) error {
|
||||||
return sendUnix(conn, data, int(f.Fd()))
|
var fds []int
|
||||||
|
if f != nil {
|
||||||
|
fds = append(fds, int(f.Fd()))
|
||||||
|
}
|
||||||
|
return sendUnix(conn, data, fds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive waits for a new message on conn, and receives its payload
|
// Receive waits for a new message on conn, and receives its payload
|
||||||
|
@ -25,15 +29,16 @@ func Receive(conn *net.UnixConn) ([]byte, *os.File, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("receive: %v", err)
|
return nil, nil, fmt.Errorf("receive: %v", err)
|
||||||
}
|
}
|
||||||
if len(fds) == 0 {
|
var f *os.File
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(fds) > 1 {
|
if len(fds) > 1 {
|
||||||
for _, fd := range fds {
|
for _, fd := range fds {
|
||||||
syscall.Close(fd)
|
syscall.Close(fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data, os.NewFile(uintptr(fds[0]), ""), nil
|
if len(fds) >= 1 {
|
||||||
|
f = os.NewFile(uintptr(fds[0]), "")
|
||||||
|
}
|
||||||
|
return data, f, nil
|
||||||
}
|
}
|
||||||
panic("impossibru")
|
panic("impossibru")
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue