gvisor: gvisor.dev/gvisor/pkg/unet Index | Files

package unet

import "gvisor.dev/gvisor/pkg/unet"

Package unet provides a minimal net package based on Unix Domain Sockets.

This does no pooling, and should only be used for a limited number of connections in a Go process. Don't use this package for arbitrary servers.

Index

Package Files

unet.go unet_unsafe.go

func SocketPair Uses

func SocketPair(packet bool) (*Socket, *Socket, error)

SocketPair creates a pair of connected sockets.

type ControlMessage Uses

type ControlMessage []byte

ControlMessage wraps around a byte array and provides functions for parsing as a Unix Domain Socket control message.

func (*ControlMessage) CloseFDs Uses

func (c *ControlMessage) CloseFDs()

CloseFDs closes the list of FDs in the control message.

Either this or ExtractFDs should be used after EnableFDs.

func (*ControlMessage) EnableFDs Uses

func (c *ControlMessage) EnableFDs(count int)

EnableFDs enables receiving FDs via control message.

This guarantees only a MINIMUM number of FDs received. You may receive MORE than this due to the way FDs are packed. To be specific, the number of receivable buffers will be rounded up to the nearest even number.

This must be called prior to ReadVec if you want to receive FDs.

func (*ControlMessage) ExtractFDs Uses

func (c *ControlMessage) ExtractFDs() ([]int, error)

ExtractFDs returns the list of FDs in the control message.

Either this or CloseFDs should be used after EnableFDs.

func (*ControlMessage) PackFDs Uses

func (c *ControlMessage) PackFDs(fds ...int)

PackFDs packs the given list of FDs in the control message.

This must be used prior to WriteVec.

func (*ControlMessage) UnpackFDs Uses

func (c *ControlMessage) UnpackFDs()

UnpackFDs clears the control message.

type ServerSocket Uses

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

ServerSocket is a bound unix domain socket.

func Bind Uses

func Bind(addr string, packet bool) (*ServerSocket, error)

Bind creates and binds a new socket.

func BindAndListen Uses

func BindAndListen(addr string, packet bool) (*ServerSocket, error)

BindAndListen creates, binds and listens on a new socket.

func NewServerSocket Uses

func NewServerSocket(fd int) (*ServerSocket, error)

NewServerSocket returns a socket from an existing FD.

func (*ServerSocket) Accept Uses

func (s *ServerSocket) Accept() (*Socket, error)

Accept accepts a new connection.

This is always blocking.

Preconditions: * ServerSocket is listening (Listen called).

func (*ServerSocket) Close Uses

func (s *ServerSocket) Close() error

Close closes the server socket.

This must only be called once.

func (*ServerSocket) FD Uses

func (s *ServerSocket) FD() int

FD returns the socket's file descriptor.

See Socket.FD.

func (*ServerSocket) Listen Uses

func (s *ServerSocket) Listen() error

Listen starts listening on the socket.

func (*ServerSocket) Release Uses

func (s *ServerSocket) Release() (int, error)

Release releases ownership of the socket's file descriptor.

See Socket.Release.

type Socket Uses

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

Socket is a connected unix domain socket.

func Connect Uses

func Connect(addr string, packet bool) (*Socket, error)

Connect connects to a server.

func NewSocket Uses

func NewSocket(fd int) (*Socket, error)

NewSocket returns a socket from an existing FD.

NewSocket takes ownership of fd.

func (*Socket) Close Uses

func (s *Socket) Close() error

Close closes the socket.

func (*Socket) FD Uses

func (s *Socket) FD() int

FD returns the FD for this Socket.

The FD is non-blocking and must not be made blocking.

N.B. os.File.Fd makes the FD blocking. Use of Release instead of FD is strongly preferred.

The returned FD cannot be used safely if there may be concurrent callers to Close or Release.

Use Release to take ownership of the FD.

func (*Socket) GetPeerCred Uses

func (s *Socket) GetPeerCred() (*syscall.Ucred, error)

GetPeerCred returns the peer's unix credentials.

func (*Socket) GetPeerName Uses

func (s *Socket) GetPeerName() ([]byte, error)

GetPeerName returns the peer name.

func (*Socket) GetSockName Uses

func (s *Socket) GetSockName() ([]byte, error)

GetSockName returns the socket name.

func (*Socket) GetSockOpt Uses

func (s *Socket) GetSockOpt(level int, name int, b []byte) (uint32, error)

GetSockOpt gets the given socket option.

func (*Socket) Read Uses

func (s *Socket) Read(p []byte) (int, error)

Read implements io.Reader.Read.

func (*Socket) Reader Uses

func (s *Socket) Reader(blocking bool) SocketReader

Reader returns a reader for this socket.

func (*Socket) Release Uses

func (s *Socket) Release() (int, error)

Release releases ownership of the socket FD.

The returned FD is non-blocking.

Any concurrent or future callers of Socket methods will receive EBADF.

func (*Socket) SetSockOpt Uses

func (s *Socket) SetSockOpt(level, name int, b []byte) error

SetSockOpt sets the given socket option.

func (*Socket) Shutdown Uses

func (s *Socket) Shutdown() error

Shutdown closes the socket for read and write.

func (*Socket) Write Uses

func (s *Socket) Write(p []byte) (int, error)

Write implements io.Writer.Write.

func (*Socket) Writer Uses

func (s *Socket) Writer(blocking bool) SocketWriter

Writer returns a writer for this socket.

type SocketReader Uses

type SocketReader struct {
    ControlMessage
    // contains filtered or unexported fields
}

SocketReader wraps an individual receive operation.

This may be used for doing vectorized reads and/or sending additional control messages (e.g. FDs). The normal entrypoint is ReadVec.

One of ExtractFDs or DisposeFDs must be called if EnableFDs is used.

func (*SocketReader) ReadVec Uses

func (r *SocketReader) ReadVec(bufs [][]byte) (int, error)

ReadVec reads into the pre-allocated bufs. Returns bytes read.

The pre-allocatted space used by ReadVec is based upon slice lengths.

This function is not guaranteed to read all available data, it returns as soon as a single recvmsg call succeeds.

type SocketWriter Uses

type SocketWriter struct {
    ControlMessage
    // contains filtered or unexported fields
}

SocketWriter wraps an individual send operation.

The normal entrypoint is WriteVec.

func (*SocketWriter) WriteVec Uses

func (w *SocketWriter) WriteVec(bufs [][]byte) (int, error)

WriteVec writes the bufs to the socket. Returns bytes written.

This function is not guaranteed to send all data, it returns as soon as a single sendmsg call succeeds.

Package unet imports 7 packages (graph) and is imported by 27 packages. Updated 2020-09-27. Refresh now. Tools for package owners.