Documentation
¶
Overview ¶
Package transport defines an interface for sending and receiving rpc messages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface { Encode(context.Context, *capnp.Message) error Decode(context.Context) (*capnp.Message, error) SetPartialWriteTimeout(time.Duration) Close() error }
A Codec is responsible for encoding and decoding messages from a single logical stream.
type Transport ¶
type Transport interface { // NewMessage allocates a new message to be sent over the transport. // The caller must call the release function when it no longer needs // to reference the message. Before releasing the message, send may be // called at most once to send the mssage, taking its cancelation and // deadline from ctx. // // Messages returned by NewMessage must have a nil CapTable. // When the returned ReleaseFunc is called, any clients in the message's // CapTable will be released. // // The Arena in the returned message should be fast at allocating new // segments. The returned ReleaseFunc MUST be safe to call concurrently // with subsequent calls to NewMessage. NewMessage(ctx context.Context) (_ rpccp.Message, send func() error, _ capnp.ReleaseFunc, _ error) // RecvMessage receives the next message sent from the remote vat. // The returned message is only valid until the release function is // called or Close is called. The release function may be called // concurrently with RecvMessage or with any other release function // returned by RecvMessage. // // Messages returned by RecvMessage must have a nil CapTable. // When the returned ReleaseFunc is called, any clients in the message's // CapTable will be released. // // The Arena in the returned message should not fetch segments lazily; // the Arena should be fast to access other segments. RecvMessage(ctx context.Context) (rpccp.Message, capnp.ReleaseFunc, error) // Close releases any resources associated with the transport. All // messages created with NewMessage must be released before calling // Close. It is not safe to call Close concurrently with any other // operations on the transport. Close() error }
A Transport sends and receives Cap'n Proto RPC messages to and from another vat.
It is safe to call NewMessage and its returned functions concurrently with RecvMessage.
func New ¶
New creates a new transport that uses the supplied codec to read and write messages across the wire.
func NewPackedStream ¶
func NewPackedStream(rwc io.ReadWriteCloser) Transport
NewPackedStream creates a new transport that uses a packed encoding.
See: NewStream.
func NewStream ¶
func NewStream(rwc io.ReadWriteCloser) Transport
NewStream creates a new transport that reads and writes to rwc. Closing the transport will close rwc.
If rwc has SetReadDeadline or SetWriteDeadline methods, they will be used to handle Context cancellation and deadlines. If rwc does not have these methods, then rwc.Close must be safe to call concurrently with rwc.Read. Notably, this is not true of *os.File before Go 1.9 (see https://golang.org/issue/7970).