Thanks to visit codestin.com
Credit goes to pkg.go.dev

reconnectingpty

package
v2.21.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateStarting is the default/start state.  Attaching will block until the
	// reconnecting pty becomes ready.
	StateStarting = iota
	// StateReady means the reconnecting pty is ready to be attached.
	StateReady
	// StateClosing means the reconnecting pty has begun closing.  The underlying
	// process may still be exiting.  Attaching will result in an error.
	StateClosing
	// StateDone means the reconnecting pty has completely shut down and the
	// process has exited.  Attaching will result in an error.
	StateDone
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Timeout describes how long to keep the pty alive without any connections.
	// Once elapsed the pty will be killed.
	Timeout time.Duration
	// Metrics tracks various error counters.
	Metrics *prometheus.CounterVec
	// BackendType specifies the ReconnectingPTY backend to use.
	BackendType string
}

Options allows configuring the reconnecting pty.

type ReconnectingPTY

type ReconnectingPTY interface {
	// Attach pipes the connection and pty, spawning it if necessary, replays
	// history, then blocks until EOF, an error, or the context's end.  The
	// connection is expected to send JSON-encoded messages and accept raw output
	// from the ptty.  If the context ends or the process dies the connection will
	// be detached.
	Attach(ctx context.Context, connID string, conn net.Conn, height, width uint16, logger slog.Logger) error
	// Wait waits for the reconnecting pty to close.  The underlying process might
	// still be exiting.
	Wait()
	// Close kills the reconnecting pty process.
	Close(err error)
}

ReconnectingPTY is a pty that can be reconnected within a timeout and to simultaneous connections. The reconnecting pty can be backed by screen if installed or a (buggy) buffer replay fallback.

func New

func New(ctx context.Context, logger slog.Logger, execer agentexec.Execer, cmd *pty.Cmd, options *Options) ReconnectingPTY

New sets up a new reconnecting pty that wraps the provided command. Any errors with starting are returned on Attach(). The reconnecting pty will close itself (and all connections to it) if nothing is attached for the duration of the timeout, if the context ends, or the process exits (buffered backend only).

type Server added in v2.18.0

type Server struct {
	ExperimentalDevcontainersEnabled bool
	// contains filtered or unexported fields
}

func NewServer added in v2.18.0

func NewServer(logger slog.Logger, commandCreator *agentssh.Server, reportConnection reportConnectionFunc,
	connectionsTotal prometheus.Counter, errorsTotal *prometheus.CounterVec,
	timeout time.Duration, opts ...func(*Server),
) *Server

NewServer returns a new ReconnectingPTY server

func (*Server) ConnCount added in v2.18.0

func (s *Server) ConnCount() int64

func (*Server) Serve added in v2.18.0

func (s *Server) Serve(ctx, hardCtx context.Context, l net.Listener) (retErr error)

type State

type State int

State represents the current state of the reconnecting pty. States are sequential and will only move forward.

Jump to

Keyboard shortcuts

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