librarian v0.2.0 SSH.Stream View Source

Defines an SSH.Stream struct returned by SSH.stream!/3, as well as key functions that are involved in accessing the ssh data from the stream struct.

Like IO.Stream, an SSH stream has side effects. Any given time you use it, the contents returned are likely to be different.

Link to this section Summary

Types

ssh protocol stream control messages

binary data sent over the server's standard out (0) or standard error (1)

messages that the local client can use to send streaming content

a lambda that acts on channel data and convert it to stream tokens

all messages that are blocked by the stream control loop.

the default tokens that can be sent for stream processing

the default tokens that can be sent for stream processing

t()

the stream data structure

Functions

sends an iodata payload to the stdin of the ssh stream

sends an end-of-file to the the ssh stream.

Link to this section Types

Specs

control_message() ::
  {:eof, SSH.chan()}
  | {:exit_status, SSH.chan(), integer()}
  | {:closed, SSH.chan()}

ssh protocol stream control messages

Specs

iostream_message() :: {:data, SSH.chan(), 0 | 1, binary()}

binary data sent over the server's standard out (0) or standard error (1)

Specs

outbound_message() :: {:send, SSH.chan(), binary()} | {:send_eof, SSH.chan()}

messages that the local client can use to send streaming content

Specs

process_fn() :: (binary(), acc :: term() -> {[term()], acc :: term()})

a lambda that acts on channel data and convert it to stream tokens

Specs

all messages that are blocked by the stream control loop.

Note that most of these are the third term in a {:ssh_cm, conn, <message>} tuple.

Link to this type

stream_control_tokens()

View Source

Specs

stream_control_tokens() :: :eof | {:retval, integer()} | :halt

the default tokens that can be sent for stream processing

Specs

stream_tokens() ::
  {:stdout, binary()}
  | {:stderr, binary()}
  | {:stream, binary()}
  | stream_control_tokens()

the default tokens that can be sent for stream processing

Specs

t() :: %SSH.Stream{
  chan: SSH.chan(),
  cmd: String.t(),
  conn: SSH.conn(),
  data: any(),
  data_timeout: timeout(),
  exit_code: non_neg_integer(),
  fds: [],
  halt: boolean(),
  on_finish: (t() -> t()),
  on_init: (t() -> t()),
  on_stderr: process_fn(),
  on_stdout: process_fn(),
  on_stream_done: (t() -> :ok | {:error, any()}),
  on_timeout: (t() -> {list(), t()}),
  stop_time: DateTime.t(),
  stream_control_messages: boolean()
}

the stream data structure

Link to this section Functions

Link to this function

send_data(stream, payload)

View Source

Specs

send_data(t(), iodata()) :: :ok

sends an iodata payload to the stdin of the ssh stream

You should use this method inside of SSH.ModuleApi.on_stderr/2, SSH.ModuleApi.on_stdout/2, and SSH.ModuleApi.on_timeout/1 functions when you're designing interactive ssh handlers. Note that this function must be called from within the same process that the stream is running on, while the stream is running.

In the future, we might write a guard that will prevent you from doing this from another process.

Specs

send_eof(t()) :: :ok

sends an end-of-file to the the ssh stream.

You should use this method inside of SSH.ModuleApi.on_stderr/2, SSH.ModuleApi.on_stdout/2, and SSH.ModuleApi.on_timeout/1 functions when you're designing interactive ssh handlers. Note that this function must be called from within the same process that the stream is running on, while the stream is running.

In the future, we might write a guard that will prevent you from doing this from another process.