ssh_server_channel(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’– ssh_server_channel πŸ’–

okay bestie, so we're looking at an Erlang module page here β€” manual section 3, no cap. sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ NAME ✨

ssh_server_channel β€” literally the behaviour -behaviour(ssh_server_channel). (It replaces ssh_daemon_channel, in case you were wondering πŸ‘€)


🌸 DESCRIPTION 🌸

bestie, read this first: this module replaces ssh_daemon_channel. the old one is still around for compatibility, but fr fr do not use it for new programs. it's not getting maintained anymore except for like... a few error corrections. it's giving legacy. πŸ’€

k so, SSH services β€” both clients and servers β€” are implemented as channels. those channels get multiplexed over an SSH connection, and they talk to each other over the SSH Connection Protocol. 🌈

this module hands you a callback API that handles all the generically-generic channel stuff for daemons, like flow control and close messages. the juicy part? your callback functions get to handle the service (application) specific parts. main character energy for your code, basically. πŸ‘‘

also, this behavior makes sure the channel process honors the principal of an OTP-process, so it can be part of a supervisor tree. not optional, bestie β€” that's a requirement of channel processes implementing a subsystem that's gonna be added to the ssh applications supervisor tree. periodt.

πŸ’… heads up: when you're implementing a client subsystem handler, use -behaviour(ssh_client_channel) instead. don't mix these up, i'm begging 😭

πŸ”₯ FUNCTIONS πŸ”₯


πŸ¦‹ CALLBACKS πŸ¦‹

handle_msg(Msg, State)

this bad boy handles all the other messages β€” y'know, the ones that aren't SSH Connection Protocol, call, or cast messages sent to the channel. so like, the random ones. πŸ™ˆ

possible Erlang 'EXIT' messages are to be handled by this function, and every single channel is to handle this following message:

{ssh_channel_up, ssh:channel_id/0 , ssh:connection_ref/0 }

  • this is the first message that the channel receives. iconic. ⭐
  • it's especially useful if the server wants to send a message to the client without first receiving a message from it. sneaky lil shortcut, love that for us.
  • if the message isn't useful for your particular scenario, just ignore it by immediately returning {ok, State}. no drama. πŸŽ€

handle_ssh_msg/2

handles SSH Connection Protocol messages that may need service-specific attention. for the deets, go look at ssh_connection:event/0. πŸ“–

the following message is taken care of by the ssh_server_channel behavior:

{closed, ssh:channel_id/0 }

  • the channel behavior sends a close message to the other side, if such a message hasn't already been sent. then it terminates the channel with reason normal. clean exit, we love a tidy queen. ✨

init(Args)

does all the necessary initializations and returns the initial channel state β€” but only if the initializations actually succeed. no fake success here. πŸ’―

the time-out values that can be returned have the same semantics as in a gen_server. and if the time-out occurs, handle_msg/2 gets called as handle_msg(timeout, State). iykyk.

terminate(Reason, State)

this function gets called by a channel process when it's about to terminate. like, the final goodbye moment. 😭

before this function is called, ssh_connection:close/2 is called β€” if it hasn't been called earlier. so no double-closing, we're civilized. πŸ’…

this function does any necessary cleaning up. when it returns, the channel process terminates with reason Reason. and the return value? ignored. not even read. it's giving "we don't need your output, just your effort." πŸ™ˆ


and that's the whole page, bestie!! this shiny lil number is from Ericsson AB, version ssh 6.0.5, and yes it's the ssh_server_channel(3) manual page. go forth and build your supervisor-tree-worthy channels, you absolute legend 🫢✨

πŸ“¦ where this page comes from