Documentation ¶
Overview ¶
Package memnet provides portable in-memory userspace "net" package implementations.
Allows portable and hermetic testing and connecting. Useful for all cases where a Unix socket would be used, but you don't actually need to cross process boundaries.
Buffered implementations are based on gVisor's Unix socket implementation.
Index ¶
- func NewBufferedPacketConnPair(network string) (*BufferedPacketConn, *BufferedPacketConn, error)
- func NewBufferedPair(network string) (net.Conn, net.Conn, error)
- func NewBufferedStreamConnPair() (*BufferedStreamConn, *BufferedStreamConn)
- func NewUnbufferedPair() (net.Conn, net.Conn)
- type BufferedListener
- func (l *BufferedListener) Accept() (net.Conn, error)
- func (l *BufferedListener) Addr() net.Addr
- func (l *BufferedListener) Close() error
- func (l *BufferedListener) Dial(laddr *net.UnixAddr) (net.Conn, error)
- func (l *BufferedListener) DialContext(ctx context.Context, laddr *net.UnixAddr) (net.Conn, error)
- func (l *BufferedListener) Shutdown()
- type BufferedPacketConn
- func (c *BufferedPacketConn) Close() error
- func (c *BufferedPacketConn) CloseRead() error
- func (c *BufferedPacketConn) CloseWrite() error
- func (c *BufferedPacketConn) LocalAddr() net.Addr
- func (c *BufferedPacketConn) Read(b []byte) (int, error)
- func (c *BufferedPacketConn) ReadFrom(b []byte) (int, net.Addr, error)
- func (c *BufferedPacketConn) RemoteAddr() net.Addr
- func (d *BufferedPacketConn) SetDeadline(t time.Time) error
- func (d *BufferedPacketConn) SetReadDeadline(t time.Time) error
- func (d *BufferedPacketConn) SetWriteDeadline(t time.Time) error
- func (c *BufferedPacketConn) Write(b []byte) (int, error)
- func (c *BufferedPacketConn) WriteTo(b []byte, addr net.Addr) (int, error)
- type BufferedStreamConn
- func (c *BufferedStreamConn) Close() error
- func (c *BufferedStreamConn) CloseRead() error
- func (c *BufferedStreamConn) CloseWrite() error
- func (c *BufferedStreamConn) LocalAddr() net.Addr
- func (c *BufferedStreamConn) Read(b []byte) (int, error)
- func (c *BufferedStreamConn) RemoteAddr() net.Addr
- func (d *BufferedStreamConn) SetDeadline(t time.Time) error
- func (d *BufferedStreamConn) SetReadDeadline(t time.Time) error
- func (d *BufferedStreamConn) SetWriteDeadline(t time.Time) error
- func (c *BufferedStreamConn) Write(b []byte) (int, error)
- type Unbuffered
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBufferedPacketConnPair ¶
func NewBufferedPacketConnPair(network string) (*BufferedPacketConn, *BufferedPacketConn, error)
NewBufferedPacketConnPair creates a connected pair (socketpair) of BufferedPacketConns.
Supported networks: "unixgram", "unixpacket".
func NewBufferedPair ¶
NewBufferedPair creates a connected pair (socketpair) of buffered in-memory net.Conns.
Supported networks: "unix", "unixgram", "unixpacket".
func NewBufferedStreamConnPair ¶
func NewBufferedStreamConnPair() (*BufferedStreamConn, *BufferedStreamConn)
NewBufferedStreamConnPair creates a connected pair (socketpair) of BufferedStreamConns.
func NewUnbufferedPair ¶
NewUnbufferedPair creates a connected pair (socketpair) of unbuffered net.Conns.
The returned values also implement net.PacketConn.
The implementation is inherently message oriented due to the lack of buffering. For each WriteXxx call, there is one opportunity to read the written data. If the buffer provided to ReadXxx is smaller than the buffer provided to the corresponding WriteXxx call, the unreadable data will be silently discarded.
Types ¶
type BufferedListener ¶
type BufferedListener struct {
// contains filtered or unexported fields
}
A BufferedListener is an in-memory Unix socket emulator that implements the net.Listener interface.
func BufferedListen ¶
func BufferedListen(network string, addr *net.UnixAddr) (*BufferedListener, error)
BufferedListen creates a new BufferedListener not in an address namespace.
Supported networks: "unix", "unixpacket".
func (*BufferedListener) Accept ¶
func (l *BufferedListener) Accept() (net.Conn, error)
Accept implements net.Conn.Accept.
func (*BufferedListener) Addr ¶
func (l *BufferedListener) Addr() net.Addr
Addr implements net.Listener.Addr.
func (*BufferedListener) Close ¶
func (l *BufferedListener) Close() error
Close implements net.Listener.Close.
func (*BufferedListener) Dial ¶
Dial creates a new net.Conn connected to the listener and optionally bound to laddr.
func (*BufferedListener) DialContext ¶
DialContext creates a new net.Conn connected to the listener and optionally bound to laddr with the option of adding cancellation and timeouts.
func (*BufferedListener) Shutdown ¶
func (l *BufferedListener) Shutdown()
Shutdown stops the listener.
type BufferedPacketConn ¶
type BufferedPacketConn struct {
// contains filtered or unexported fields
}
A BufferedPacketConn is an in-memory Unix dgram/seqpacket socket emulator that implements the net.Conn and net.PacketConn interfaces.
Effectively equivalent to the "unixgram" and "unixpacket" networks (SOCK_DGRAM and SOCK_SEQPACKET socket types respectively), message boundaries are not preserved, but bytes are transferred reliably and in the order that they were sent. ReadXxx calls will read the next available bytes and any remaining unread bytes will be available to the next ReadXxx call.
func (*BufferedPacketConn) Close ¶
func (c *BufferedPacketConn) Close() error
Close implements net.PacketConn.Close.
func (*BufferedPacketConn) CloseRead ¶
func (c *BufferedPacketConn) CloseRead() error
CloseRead shuts down the reading side of the connection. Most callers should just use Close.
A Half-Close is performed the same as CloseRead for *net.UnixConn.
func (*BufferedPacketConn) CloseWrite ¶
func (c *BufferedPacketConn) CloseWrite() error
CloseWrite shuts down the writing side of the connection. Most callers should just use Close.
A Half-Close is performed the same as CloseWrite for *net.UnixConn.
func (*BufferedPacketConn) LocalAddr ¶
func (c *BufferedPacketConn) LocalAddr() net.Addr
LocalAddr implements net.Conn.LocalAddr.
func (*BufferedPacketConn) Read ¶
func (c *BufferedPacketConn) Read(b []byte) (int, error)
Read implements net.Conn.Read.
func (*BufferedPacketConn) RemoteAddr ¶
func (c *BufferedPacketConn) RemoteAddr() net.Addr
RemoteAddr implements net.Conn.RemoteAddr.
func (*BufferedPacketConn) SetDeadline ¶
SetDeadline implements net.Conn.SetDeadline and net.PacketConn.SetDeadline.
func (*BufferedPacketConn) SetReadDeadline ¶
SetReadDeadline implements net.Conn.SetReadDeadline and net.PacketConn.SetReadDeadline.
func (*BufferedPacketConn) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn.SetWriteDeadline and net.PacketConn.SetWriteDeadline.
type BufferedStreamConn ¶
type BufferedStreamConn struct {
// contains filtered or unexported fields
}
A BufferedStreamConn is an in-memory Unix stream socket emulator that implements the net.Conn interface.
Emulates the "unix" network in the net package (SOCK_STREAM), message boundaries are not preserved, but bytes are transferred reliably and in the order that they were sent. ReadXxx calls will read the next available bytes and any remaining unread bytes will be available to the next ReadXxx call.
func (*BufferedStreamConn) Close ¶
func (c *BufferedStreamConn) Close() error
Close implements net.Conn.Close.
func (*BufferedStreamConn) CloseRead ¶
func (c *BufferedStreamConn) CloseRead() error
CloseRead shuts down the reading side of the connection. Most callers should just use Close.
A Half-Close is performed the same as CloseRead for *net.UnixConn.
func (*BufferedStreamConn) CloseWrite ¶
func (c *BufferedStreamConn) CloseWrite() error
CloseWrite shuts down the writing side of the connection. Most callers should just use Close.
A Half-Close is performed the same as CloseWrite for *net.UnixConn.
func (*BufferedStreamConn) LocalAddr ¶
func (c *BufferedStreamConn) LocalAddr() net.Addr
LocalAddr implements net.Conn.LocalAddr.
func (*BufferedStreamConn) Read ¶
func (c *BufferedStreamConn) Read(b []byte) (int, error)
Read implements net.Conn.Read.
func (*BufferedStreamConn) RemoteAddr ¶
func (c *BufferedStreamConn) RemoteAddr() net.Addr
RemoteAddr implements net.Conn.RemoteAddr.
func (*BufferedStreamConn) SetDeadline ¶
SetDeadline implements net.Conn.SetDeadline and net.PacketConn.SetDeadline.
func (*BufferedStreamConn) SetReadDeadline ¶
SetReadDeadline implements net.Conn.SetReadDeadline and net.PacketConn.SetReadDeadline.
func (*BufferedStreamConn) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn.SetWriteDeadline and net.PacketConn.SetWriteDeadline.
type Unbuffered ¶
type Unbuffered struct {
// contains filtered or unexported fields
}
Unbuffered is an unbuffered net.Listener implemented in memory in userspace.
Lighter weight, but not compatible with all applications. Creates unbuffered net.Conns.
func NewUnbuffered ¶
func NewUnbuffered() *Unbuffered
NewUnbuffered creates a new unbuffered listener.
func (*Unbuffered) Accept ¶
func (u *Unbuffered) Accept() (net.Conn, error)
Accept implements net.Listener.Accept.
func (*Unbuffered) Dial ¶
func (u *Unbuffered) Dial() (net.Conn, error)
Dial creates a new unbuffered connection with no timeout.
func (*Unbuffered) DialContext ¶
DialContext creates a new unbuffered connection with a context.
Directories ¶
Path | Synopsis |
---|---|
Package unix contains the implementation of Unix endpoints.
|
Package unix contains the implementation of Unix endpoints. |
linux
Package linux provides Linux constants.
|
Package linux provides Linux constants. |
refs
Package refs defines an interface for reference counted objects.
|
Package refs defines an interface for reference counted objects. |
syserr
Package syserr contains sandbox-internal errors.
|
Package syserr contains sandbox-internal errors. |
tcpip
Package tcpip provides the interfaces and related types that users of the tcpip stack will use in order to create endpoints used to send and receive data over the network stack.
|
Package tcpip provides the interfaces and related types that users of the tcpip stack will use in order to create endpoints used to send and receive data over the network stack. |
tcpip/buffer
Package buffer provides the implementation of a buffer view.
|
Package buffer provides the implementation of a buffer view. |
waiter
Package waiter provides the implementation of a wait queue, where waiters can be enqueued to be notified when an event of interest happens.
|
Package waiter provides the implementation of a wait queue, where waiters can be enqueued to be notified when an event of interest happens. |