package multiplex
import "github.com/containerd/nri/pkg/net/multiplex"
Index ¶
Types ¶
type ConnID ¶
type ConnID uint32
ConnID uniquely identifies a logical connection within a Mux.
const ( // PluginServiceConn is the mux connection ID for NRI plugin services. PluginServiceConn ConnID = iota + 1 // RuntimeServiceConn is the mux connection ID for NRI runtime services. RuntimeServiceConn )
const ( // LowestConnID is the lowest externally usable ConnID. LowestConnID ConnID )
type Mux ¶
type Mux interface { // Open the connection for the given ConnID. Open(ConnID) (net.Conn, error) // Close the Mux and all connections associated with it. Close() error // Dialer returns a net.Dial-like function for the connection. // // Calling the returned function (with arguments) will return a // net.Conn for the connection. Dialer(ConnID) func(string, string) (net.Conn, error) // Listener returns a net.Listener for the connection. The first // call to Accept() on the listener will return a net.Conn for the // connection. Subsequent calls to Accept() will block until the // connection is closed then return io.EOF. Listen(ConnID) (net.Listener, error) // Trunk returns the trunk connection for the Mux. Trunk() net.Conn // Unblock unblocks the Mux reader. Unblock() }
Mux multiplexes several logical connections over a single net.Conn.
Connections are identified within a Mux by ConnIDs which are simple 32-bit unsigned integers. Opening a connection returns a net.Conn corrponding to the ConnID. This can then be used to write and read data through the connection with the Mux performing multiplexing and demultiplexing of data.
Writing to a connection is fully synchronous. The caller can safely reuse the buffer once the call returns. Reading from a connection returns the oldest demultiplexed buffer for the connection, blocking if the connections incoming queue is empty. If any incoming queue is ever overflown the underlying trunk and all multiplexed connections are closed and an error is recorded. This error is later returned by any subsequent read from any connection. All connections of the Mux have the same fixed incoming queue length which can be configured using the WithReadQueueLength Option during Mux creation.
The Mux interface also provides functions that emulate net.Dial and net.Listen for a connection. Usually these can be used for passing multiplexed connections to packages that insist to Dial or Accept themselves for connection establishment.
Note that opening a connection is a virtual operation in the sense that it has no effects outside the Mux. It is performed without any signalling or other communication. It merely acquires the net.Conn corresponding to the connection and blindly assumes that the same ConnID is or will be opened at the other end of the Mux.
func Multiplex ¶
Multiplex returns a multiplexer for the given connection.
type Option ¶
type Option func(*mux)
Option to apply to a Mux.
func WithBlockedRead ¶
func WithBlockedRead() Option
WithBlockedRead causes the Mux to be blocked for reading until gets Unblock()'ed.
func WithReadQueueLength ¶
WithReadQueueLength overrides the default read queue size.
Source Files ¶
- Version
- v0.9.0 (latest)
- Published
- Dec 12, 2024
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 2 months ago –
Tools for package owners.