fdsrv

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Serves a file descriptor over an AF_UNIX socket when presented with a nonce.

You must pass the socket path and nonce to the client via some out-of-band mechanism, such as gRPC or a bash script.

Notes: - Uses the unix domain socket abstract namespace - Picks its own path in the abstract namespace for the socket. - Shared FDs are essentially duped, and they point to the same struct file: they share offsets and whatnot.

Options: - WithServeOnce: serve once and shuts down (default is forever) - WithTimeout: cancel itself after a timeout (default none)

Usage Server:

fds, err := NewServer(fd_to_share, "some_nonce", WithServeOnce())
var s path = fds.UDSPath()

// Pass path and some_nonce to the client via an out of band mechanism

fds.Serve(); // Blocks until the server is done
fds.Close()

Usage Client:

sfd, err := GetSharedFD("uds_path", "some_nonce")

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTruncatedWrite   = errors.New("truncated write")
	ErrEmptyNonce       = errors.New("nonce must not be empty")
	ErrMissingSCM       = errors.New("missing socket control message")
	ErrNotOneUnixRights = errors.New("expected exactly one unix rights")
)

Functions

func GetSharedFD

func GetSharedFD(udsPath, nonce string) (int, error)

GetSharedFD gets an FD served at udsPath with nonce

func WithServeOnce

func WithServeOnce() func(*Server) error

WithServeOnce sets the "serve once and exit" option to NewServer

func WithTimeout

func WithTimeout(timeout time.Duration) func(*Server) error

WithTimeOut adds a timeout option to NewServer

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(fd int, nonce string, options ...func(*Server) error) (*Server, error)

NewServer creates a server. Close() it when you're done.

func (*Server) Close

func (fds *Server) Close()

Close closes the server

func (*Server) Serve

func (fds *Server) Serve() error

Serve serves the FD

func (*Server) UDSPath

func (fds *Server) UDSPath() string

UDSPath returns the Unix Domain Socket path the server is listening on

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL