Help us shape the future of Go! Take the 2026 Go Developer Survey

stream

package
v0.57.20 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageTooLarge = errors.New("message exceeds the maximum message size")

ErrMessageTooLarge is returned by a message pipe Write longer than the pipe's maximum message size.

Functions

func NewMessagePipe

func NewMessagePipe(maxSize int) (MessageStream, MessageStream)

NewMessagePipe returns the two connected ends of an in-memory MessageStream. Messages longer than maxSize fail to Write, as messages larger than one packet fail on a link. The control streams are a net.Pipe.

Types

type MessageStream

type MessageStream interface {
	Stream

	// Control returns the reliable stream of this message stream.
	Control() Stream
}

MessageStream is a stream opened with OpenOpts.Unreliable.

Each Write sends one message and each Read returns one whole message. Messages are delivered at most once, possibly out of order, and a lost message is never retransmitted. Write fails when a message exceeds the size the link can send in one packet; Read fails with io.ErrShortBuffer when b is too small for the next message, which is then dropped.

Control is the reliable stream the message stream was negotiated on. It stays open for the stream's lifetime and carries whatever the protocol needs delivered reliably. Close closes both.

type OpenOpts

type OpenOpts struct {
	// Unreliable opens a MessageStream: its messages may be lost or arrive
	// out of order, so a lost message never delays the ones after it.
	Unreliable bool
}

OpenOpts are optional arguments when opening a stream.

type Stream

type Stream interface {
	// Read data from the stream.
	Read(b []byte) (n int, err error)
	// Write data to the stream.
	Write(b []byte) (n int, err error)
	// SetReadDeadline sets the read deadline as defined by
	// A zero time value disables the deadline.
	SetReadDeadline(t time.Time) error
	// SetWriteDeadline sets the write deadline as defined by
	// A zero time value disables the deadline.
	SetWriteDeadline(t time.Time) error
	// SetDeadline sets both read and write deadlines as defined by
	// A zero time value disables the deadlines.
	SetDeadline(t time.Time) error
	// Close closes both directions of the stream. A pending Read returns.
	Close() error
}

Stream is a stream-based data channel between two peers over a link.

Directories

Path Synopsis
api
rpc
Package stream_datagram forwards UDP packets over an established peer message stream.
Package stream_datagram forwards UDP packets over an established peer message stream.

Jump to

Keyboard shortcuts

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