Documentation
¶
Overview ¶
Package transport defines the Transport interface and ships three concrete implementations: an in-memory pair (for tests and same- process embedders), a WebSocket transport, and an NDJSON-over-stdio transport.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("transport: closed")
ErrClosed is returned by Send and Recv after the transport is closed.
Functions ¶
func NewMemoryPair ¶
NewMemoryPair returns two transports connected via in-memory channels. Send on one returns Recv on the other. Useful for same-process tests and embedders.
Types ¶
type Transport ¶
type Transport interface {
// Send delivers env to the peer, applying transport-specific
// framing.
Send(ctx context.Context, env arcp.Envelope) error
// Recv blocks until the next envelope arrives, ctx is done, or the
// transport closes.
Recv(ctx context.Context) (arcp.Envelope, error)
// Close terminates the transport. Subsequent Send calls return
// ErrClosed; pending Recv calls unblock with io.EOF or an
// equivalent wrapped error. Safe to call more than once.
Close() error
}
Transport is the bidirectional envelope channel for one ARCP connection. Each side of a session holds exactly one Transport.
Implementations MUST honour ctx for both Send and Recv: both calls MUST return promptly when ctx.Done() is closed. Send and Recv MAY be called concurrently from different goroutines, but each end is expected to be driven by a single reader and a single writer.
func DialWebSocket ¶
DialWebSocket opens a client WebSocket transport to url.
func NewStdioTransport ¶
NewStdioTransport wraps an io.Reader / io.Writer pair as a Transport using NDJSON framing (one JSON envelope per line). Closes the reader and writer (if they are io.Closer) when Close is called.
func NewWebSocket ¶
NewWebSocket wraps an established websocket.Conn as a Transport. The transport takes ownership of conn; Close releases it.
type WebSocketOptions ¶
type WebSocketOptions struct {
// Subprotocols is the list of WebSocket subprotocols to negotiate.
// Empty means "no subprotocol".
Subprotocols []string
// HTTPHeader is sent on the dial request (clients only).
HTTPHeader http.Header
// HTTPClient overrides the dial client. Optional.
HTTPClient *http.Client
// ReadLimit caps the inbound frame size in bytes. Zero uses 1 MiB.
ReadLimit int64
}
WebSocketOptions configures a WebSocket transport.