escape

package
v4.3.6-dev.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package escape implements client-side escape character logic. This logic mimics OpenSSH: https://man.openbsd.org/ssh#ESCAPE_CHARACTERS.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDisconnect is returned when the user has entered a disconnect
	// sequence, requesting connection to be interrupted.
	ErrDisconnect = errors.New("disconnect escape sequence detected")
	// ErrTooMuchBufferedData is returned when the Reader's internal buffer has
	// filled over 10MB. Either the consumer of Reader can't keep up with the
	// data or it's entirely stuck and not consuming the data.
	ErrTooMuchBufferedData = errors.New("internal buffer has grown too big")
)

Functions

This section is empty.

Types

type Reader

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

Reader is an io.Reader wrapper that catches OpenSSH-like escape sequences in the input stream. See NewReader for more info.

Reader is safe for concurrent use.

func NewReader

func NewReader(in io.Reader, out io.Writer, onDisconnect func(error)) *Reader

NewReader creates a new Reader to catch escape sequences from 'in'.

Two sequences are supported:

  • "~?": prints help text to 'out' listing supported sequences
  • "~.": disconnect stops any future reads from in; after this sequence, callers can still read any unread data up to this sequence from Reader but all future Read calls will return ErrDisconnect; onDisconnect will also be called with ErrDisconnect immediately

NewReader starts consuming 'in' immediately in the background. This allows Reader to detect sequences without the caller actively calling Read (such as when it's stuck writing out the received data).

Unread data is accumulated in an internal buffer. If this buffer grows to a limit (currently 10MB), Reader will stop permanently. onDisconnect will get called with ErrTooMuchBufferedData. Read can still be called to consume the internal buffer but all future reads after that will return ErrTooMuchBufferedData.

If the internal buffer is empty, calls to Read will block until some data is available or an error occurs.

func (*Reader) Read

func (r *Reader) Read(buf []byte) (int, error)

Read fills buf with available data. If no data is available, Read will block.

Jump to

Keyboard shortcuts

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