channel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 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 channel defines the protocol-neutral lifecycle of an established bidirectional byte stream.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilStream is returned when a Stream is created without an underlying
	// bidirectional byte stream.
	ErrNilStream = errors.New("channel stream must not be nil")
	// ErrNotOpen is returned when I/O is attempted after a Channel has stopped
	// accepting reads or writes.
	ErrNotOpen = errors.New("channel is not open")
	// ErrResizeUnsupported is returned when a Channel has no terminal-size
	// capability.
	ErrResizeUnsupported = errors.New("channel does not support terminal resizing")
)

Functions

This section is empty.

Types

type Channel

type Channel interface {
	Read(p []byte) (int, error)
	Write(p []byte) (int, error)
	Close() error
	State() State
}

Channel is an established, protocol-neutral bidirectional byte stream.

Implementations own the live stream resource until Close returns. Read and Write follow the standard library contracts and must not retain caller-owned buffers. Close must be safe to call repeatedly. State is a point-in-time lifecycle snapshot and must not be used as a concurrency guard.

type Resizer

type Resizer interface {
	Resize(cols, rows uint16) error
}

Resizer is an optional Channel capability for terminal-like streams.

Generic Session behavior does not require this capability. Terminal adapters may request it without making file, debug, or other byte streams implement a meaningless terminal operation.

type State

type State uint8

State describes the lifecycle stage of an established Channel.

const (
	// StateOpen indicates that the Channel accepts reads and writes.
	StateOpen State = iota
	// StateClosing indicates that Close is releasing the underlying stream.
	StateClosing
	// StateClosed indicates that Close has finished.
	StateClosed
	// StateFailed indicates that an underlying read or write failed.
	StateFailed
)

func (State) String

func (s State) String() string

String returns the stable lowercase form of a State for diagnostics.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream gives an io.ReadWriteCloser Channel lifecycle and idempotent cleanup.

Stream is useful when a Transport opens a standard Go byte stream that does not need additional Channel capabilities.

func NewStream

func NewStream(stream io.ReadWriteCloser) (*Stream, error)

NewStream takes ownership of an already-open stream and returns an open Channel. The stream remains owned by Stream until Close completes.

func (*Stream) Close

func (s *Stream) Close() error

Close releases the underlying stream exactly once and returns the original cleanup result to sequential or concurrent callers.

func (*Stream) Read

func (s *Stream) Read(p []byte) (int, error)

Read copies bytes from the underlying stream while the Channel is open.

func (*Stream) State

func (s *Stream) State() State

State returns a synchronized snapshot of the Channel lifecycle.

func (*Stream) Write

func (s *Stream) Write(p []byte) (int, error)

Write copies bytes to the underlying stream while the Channel is open.

Jump to

Keyboard shortcuts

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