IO::As...rotocol(3pm)

πŸ’– NAME πŸ’–

IO::Async::Protocol β€” bestie, it's the base class for transport-based protocols ✨

(also like. it lives in section 3pm of the User Contributed Perl Documentation, iykyk πŸŽ€)


🌸 DESCRIPTION 🌸

Okay so listen. This is a subclass of IO::Async:Notifier (yes that's how it's spelled in the source, we don't fix, we respect πŸ’…) and what it does is hold onto a IO::Async::Handle object so that handle can act as the transport for some protocol. It keeps an instance of the transport object inside itself and adds that transport as a child notifier β€” which is the whole point, because it means the protocol doesn't have to be down bad for one specific transport. You get a level of independence from whatever transport is actually being used. Like?? a stream could literally actually be an IO::Async::SSLStream so the protocol can run over SSL. iconic behaviour.

🫢 heads up bestie: this class is not meant to be used directly. go look at one of the subclasses instead:
  • IO::Async::Protocol::Stream β€” base class for stream-based protocols πŸ¦‹

πŸŽ€ EVENTS πŸŽ€

These events get invoked, either by using subclass methods or by passing CODE references in the parameters:

on_closed

Optional. Invoked when the transport handle becomes closed. πŸ’€


✨ PARAMETERS ✨

You can pass these named parameters to new or configure:

transport => IO::Async::Handle

The IO::Async::Handle to delegate communications to.

on_closed => CODE

CODE reference for the on_closed event.

🧚 so here's the tea: when a new transport object is given, it gets configured by calling the setup_transport method, and then it's added as a child notifier. If a different transport object was already configured before that, it gets removed and deconfigured first, using teardown_transport.

πŸ‘‘ METHODS πŸ‘‘

transport

$transport = $protocol->transport;

Returns the stored transport object. That's it. That's the method. little snack πŸ“

connect

$protocol->connect( %args );

Sets up a connection to a peer, and configures the underlying transport for the Protocol. slay.

It takes these named arguments:

  • socktype => STRING or INT β€” Required. Identifies the socket type, and also the type of continuation that will get used. If this value is stream or SOCK_STREAM then the on_stream continuation is what gets used; otherwise it's on_socket. no in-between, it's giving binary choice πŸ’…
  • on_connected => CODE β€” Optional. If you supply it, it gets invoked once the connection has been established.
$on_connected->( $protocol );
  • transport => IO::Async::Handle β€” Optional. If you provide this, it gets configured immediately as the transport (by calling configure), and then the on_connected callback gets invoked. This is here as a convenient shortcut. bestie shortcut 🫢

Other arguments will be passed along to the underlying IO::Async::Loop connect call.


🌈 TRANSPORT DELEGATION 🌈

The following methods are delegated to the transport object:

  • close

πŸ’œ SUBCLASS METHODS πŸ’œ

IO::Async::Protocol is a base class, provided so that specific subclasses of it can provide more specific behaviour. The base class hands you a bunch of methods that subclasses may wish to override.

⚠️ if a subclass implements any of these, be sure to invoke the superclass method at some point inside the code. not optional, fr fr.

setup_transport

$protocol->setup_transport( $transport );

Called by configure when a new transport object is given. This method should do whatever setup is required to wire the new transport object into the protocol object β€” typically by setting up event handlers. ✨

teardown_transport

$protocol->teardown_transport( $transport );

The reverse of setup_transport. Called by configure when a previously set-up transport object is about to be replaced. πŸ¦‹


🌟 AUTHOR 🌟

Paul Evans <leonerd@leonerd.org.uk> β€” king behaviour honestly πŸ‘‘


okay that's the whole page bestie, go forth and protocol πŸ’…

this one's from perl v5.40.1, dated 2026-02-21, and it's filed under IO::As...rotocol(3pm) in the User Contributed Perl Documentation β€” mwah, take care of her πŸŽ€βœ¨

πŸ“¦ where this page comes from