summaryrefslogtreecommitdiffhomepage
path: root/pkg/fd/fd.go
diff options
context:
space:
mode:
authorRobert Tonic <btonic@users.noreply.github.com>2019-07-29 14:57:14 -0700
committerRobert Tonic <btonic@users.noreply.github.com>2019-08-27 13:08:56 -0400
commitc319b360d134cff66000fd036fce8b3816c296ea (patch)
treeb0037d1a8fd29b4ec765b6e2ca08e8eb5ced81b8 /pkg/fd/fd.go
parentb4cdaef4a1d545867d8e34036c5ed3175e55079d (diff)
First pass at implementing Unix Domain Socket support. No tests.
This commit adds support for detecting the socket file type, connecting to a Unix Domain Socket, and providing bidirectional communication (without file descriptor transfer support).
Diffstat (limited to 'pkg/fd/fd.go')
-rw-r--r--pkg/fd/fd.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/fd/fd.go b/pkg/fd/fd.go
index 83bcfe220..c3acd0fe2 100644
--- a/pkg/fd/fd.go
+++ b/pkg/fd/fd.go
@@ -22,6 +22,7 @@ import (
"runtime"
"sync/atomic"
"syscall"
+ "net"
)
// ReadWriter implements io.ReadWriter, io.ReaderAt, and io.WriterAt for fd. It
@@ -185,6 +186,21 @@ func OpenAt(dir *FD, path string, flags int, mode uint32) (*FD, error) {
return New(f), nil
}
+// OpenUnix TODO: DOC
+func OpenUnix(path string) (*FD, error) {
+ addr, _ := net.ResolveUnixAddr("unix", path)
+ f, err := net.DialUnix("unix", nil, addr); if err != nil {
+ return nil, fmt.Errorf("unable to open socket: %q, err: %v", path, err)
+ }
+ fConnd, err := f.File(); if err != nil {
+ return nil, fmt.Errorf("unable to convert to os.File: %q, err: %v", path, err)
+ }
+ fdConnd, err := NewFromFile(fConnd); if err != nil {
+ return nil, fmt.Errorf("unable to convert os.File to fd.FD: %q, err: %v", path, err)
+ }
+ return fdConnd, nil
+}
+
// Close closes the file descriptor contained in the FD.
//
// Close is safe to call multiple times, but will return an error after the