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 newtransportobject is given, it gets configured by calling thesetup_transportmethod, 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, usingteardown_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 => STRINGorINTβ Required. Identifies the socket type, and also the type of continuation that will get used. If this value isstreamorSOCK_STREAMthen theon_streamcontinuation is what gets used; otherwise it'son_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 callingconfigure), and then theon_connectedcallback 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
- ubuntu stonking: libio-async-perl 0.805-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms