table of contents
- stretch 1:19.2.1+dfsg-2+deb9u2
ssh_channel(3erl) | Erlang Module Definition | ssh_channel(3erl) |
NAME¶
ssh_channel - -behaviour(ssh_channel).DESCRIPTION¶
SSH services (clients and servers) are implemented as channels that are multiplexed over an SSH connection and communicates over the SSH Connection Protocol. This module provides a callback API that takes care of generic channel aspects, such as flow control and close messages. It lets the callback functions take care of the service (application) specific parts. This behavior also ensures that the channel process honors the principal of an OTP-process so that it can be part of a supervisor tree. This is a requirement of channel processes implementing a subsystem that will be added to the ssh applications supervisor tree.DATA TYPES¶
Type definitions that are used more than once in this module, or abstractions to indicate the intended use of the data type, or both:- boolean() =:
- true | false
- string() =:
- list of ASCII characters
- timeout() =:
- infinity | integer() in milliseconds
- ssh_connection_ref() =:
- opaque() -as returned by ssh:connect/3 or sent to an SSH channel process
- ssh_channel_id() =:
- integer()
- ssh_data_type_code() =:
- 1 ("stderr") | 0 ("normal") are the valid values, see RFC 4254 Section 5.2
EXPORTS¶
call(ChannelRef, Msg) ->call(ChannelRef, Msg, Timeout) -> Reply | {error, Reason}
Types:
Timeout = timeout()
Reply = term()
Reason = closed | timeout
Makes a synchronous call to the channel process by sending a message and waiting until a reply arrives, or a time-out occurs. The channel calls Module:handle_call/3 to handle the message. If the channel process does not exist, {error, closed} is returned.
cast(ChannelRef, Msg) -> ok
Types:
Sends an asynchronous message to the channel process and returns ok immediately, ignoring if the destination node or channel process does not exist. The channel calls Module:handle_cast/2 to handle the message.
enter_loop(State) -> _
Types:
Makes an existing process an ssh_channel process. Does not return, instead the calling process enters the ssh_channel process receive loop and become an ssh_channel process. The process must have been started using one of the start functions in proc_lib, see the proc_lib(3erl) manual page in STDLIB. The user is responsible for any initialization of the process and must call ssh_channel:init/1.
init(Options) -> {ok, State} | {ok, State, Timeout} | {stop,
Reason}
Types:
State = term()
Timeout = timeout()
Reason = term()
The following options must be present:
- {channel_cb, atom()}:
- The module that implements the channel behaviour.
- {init_args(), list()}:
- The list of arguments to the init function of the callback module.
- {cm, connection_ref()}:
- Reference to the ssh connection as returned by ssh:connect/3
- {channel_id, channel_id()}:
- Id of the ssh channel.
reply(Client, Reply) -> _
Types:
Reply = term()
This function can be used by a channel to send a reply to a client that called call/[2,3] when the reply cannot be defined in the return value of Module:handle_call/3.
Client must be the From argument provided to the callback function handle_call/3. Reply is an arbitrary term, which is given back to the client as the return value of ssh_channel:call/[2,3].
start(SshConnection, ChannelId, ChannelCb, CbInitArgs)
->
start_link(SshConnection, ChannelId, ChannelCb, CbInitArgs) -> {ok,
ChannelRef} | {error, Reason}
Types:
ChannelId = ssh_channel_id()
Starts a process that handles an SSH channel. It is called internally, by the ssh daemon, or explicitly by the ssh client implementations. The behavior sets the trap_exit flag to true.
CALLBACK TIME-OUTS¶
The time-out values that can be returned by the callback functions have the same semantics as in a gen_server. If the time-out occurs, handle_msg/2 is called as handle_msg(timeout, State).EXPORTS¶
Module:code_change(OldVsn, State, Extra) -> {ok, NewState}Types:
Converts process state when code is changed.
This function is called by a client-side channel when it is to update its internal state during a release upgrade or downgrade, that is, when the instruction {update,Module,Change,...}, where Change={advanced,Extra}, is given in the appup file. For more information, refer to Section 9.11.6 Release Handling Instructions in the System Documentation.
Module:init(Args) -> {ok, State} | {ok, State, timeout()} |
{stop, Reason}
Types:
Reason = term()
Makes necessary initializations and returns the initial channel state if the initializations succeed.
For more detailed information on time-outs, see Section CALLBACK TIME-OUTS.
Module:handle_call(Msg, From, State) -> Result
Types:
From = opaque()
Result = {reply, Reply, NewState} | {reply, Reply, NewState, timeout()} | {noreply, NewState} | {noreply , NewState, timeout()} | {stop, Reason, Reply, NewState} | {stop, Reason, NewState}
Reply = term()
Reason = term()
Handles messages sent by calling ssh_channel:call/[2,3]
For more detailed information on time-outs,, see Section CALLBACK TIME-OUTS.
Module:handle_cast(Msg, State) -> Result
Types:
State = term()
Result = {noreply, NewState} | {noreply, NewState, timeout()} | {stop, Reason, NewState}
NewState = term()
Reason = term()
Handles messages sent by calling ssh_channel:cast/2.
For more detailed information on time-outs, see Section CALLBACK TIME-OUTS.
Module:handle_msg(Msg, State) -> {ok, State} | {stop,
ChannelId, State}
Types:
ChannelId = ssh_channel_id()
State = term()
Handles other messages than SSH Connection Protocol, call, or cast messages sent to the channel.
Possible Erlang 'EXIT' messages is to be handled by this function and all channels are to handle the following message.
- {ssh_channel_up, ssh_channel_id(), ssh_connection_ref()}:
- This is the first message that the channel receives. It is sent just before the ssh_channel:init/1 function returns successfully. This is especially useful if the server wants to send a message to the client without first receiving a message from it. If the message is not useful for your particular scenario, ignore it by immediately returning {ok, State}.
Module:handle_ssh_msg(Msg, State) -> {ok, State} | {stop,
ChannelId, State}
Types:
ChannelId = ssh_channel_id()
State = term()
Handles SSH Connection Protocol messages that may need service-specific attention. For details, see ssh_connection:event().
The following message is taken care of by the ssh_channel behavior.
- {closed, ssh_channel_id()}:
- The channel behavior sends a close message to the other side, if such a message has not already been sent. Then it terminates the channel with reason normal.
Module:terminate(Reason, State) -> _
Types:
State = term()
This function is called by a channel process when it is about to terminate. Before this function is called, ssh_connection:close/2 is called, if it has not been called earlier. This function does any necessary cleaning up. When it returns, the channel process terminates with reason Reason. The return value is ignored.
ssh 4.4 | Ericsson AB |