transport

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var ErrClosed = errors.New("transport: closed")

ErrClosed is returned by Send and Recv after the transport is closed.

Functions

func NewMemoryPair

func NewMemoryPair() (Transport, Transport)

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

func DialWebSocket(ctx context.Context, url string, opts WebSocketOptions) (Transport, error)

DialWebSocket opens a client WebSocket transport to url.

func NewStdioTransport

func NewStdioTransport(in io.Reader, out io.Writer) Transport

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

func NewWebSocket(conn *websocket.Conn) Transport

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL