AnyEve...ection(3pm)
π¦ NAME π¦
AnyEvent::Connection β the base class for tcp connectful clients, bestie π
This page is from the User Contributed Perl Documentation set, man section 3pm (so: a Perl module page, not a command you run in your shell, okay?).
β¨ SYNOPSIS β¨
package MyTCPClient;
use base 'AnyEvent::Connection';
package main;
my $client = MyTCPClient->new(
host => 'localhost',
port => 12345,
);
$client->reg_cb(
connected => sub {
my ($client,$connection,$host,$port) = @_;
# ...
$client->after(
$interval, sub {
# Called after interval, if connection still alive
}
);
}
connfail = sub {
my ($client,$reason) = @_;
# ...
},
disconnect => sub {
my ($client,$reason) = @_;
},
error => sub {
my ($client,$error) = @_;
# Called in error conditions for callbackless methods
},
);
$client->connect;
π«Ά ngl theconnfail = subline in the original really does use a single=and not=>, and I'm not touching it β verbatim means verbatim, periodt.
π EVENTS π
connected ($connobject, $host, $port)β fires the moment your client actually gets connected πconnfailβ fires when the client fails to connect π (it's giving "we tried, bestie")disconnectβ fires whenever the client disconnectserrorβ fires in error conditions for callbackless methods, like fr fr when you callpush_writeon a client that isn't connected π
π OPTIONS π
hostβ the host to connect toportβ the port to connect totimeout[ = 3 ] β connect/read/write timeout, measured in seconds β±οΈreconnect[ = 1 ] β if it's true, automatically reconnect after a disconnect/connfail, after a delay of$reconnectsecondsrawcon[ =AnyEvent::Connection::Raw] β the class that implements the low-level connection π
π OPERATION METHODS π
newβ Cleates connection object (peep OPTIONS above for what you can pass in π)connectβ begin the connection, let's goooodisconnect ($reason)β close the current connection.reasonis optional, no pressurereconnectβ close the current connection and establish a brand new one π¦after($interval, $cb->())β helper method. It'sAE::timer(after), associated with the current connection.
It will be destroyed if the connection is destroyed, so there's no timer invocation after the connection gets destroyed. clean. β¨
periodic($interval, $cb->())β helper method. It'sAE::timer(periodic), associated with the current connection.
Same deal: it will be destroyed if the connection is destroyed, so no timer invocation after the connection is destroyed. π
periodic_stop()β if you call this from inside the periodic callback, the periodic will be stopped. iconic:
my $count;
$client->periodic(1,sub {
$client->periodic_stop if ++$count > 10;
});
# callback will be called only 10 times;
destroyβ close the connection, destroy all associated objects and timers, and clean self π§Ή
π CONNECT METHODS π
Once you're connected, there are some methods that get proxied to the raw connection or to AE::Handle. slay.
push_writeβ seeAE::Handle::push_writepush_readβ seeAE::Handle::push_readunshift_readβ seeAE::Handle::unshift_readsayβ same aspush_write+ a newlinereplyβ same aspush_write+ a newline
Now for the next methods there's a lil feature: the callback will be called in any way β either by successful processing, or by error, or by object destruction. every single time, bestie.
recv($bytes, %args, cb => $cb->())β similar to:
$fh->push_read(chunk => $bytes, $cb->());
command($data, %args, cb => $cb->())β similar to:
$fh->push_write($data);
$fh->push_read(line => $cb->());
πΈ AUTHOR πΈ
Mons Anderson, "<mons at cpan.org>" π
π BUGS π
Please report any bugs or feature requests to "bug-anyevent-connection at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-Connection>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so you're never left on read, fr fr π«Ά
β SUPPORT β
You can find documentation for this module with the perldoc command.
perldoc AnyEvent::Connection
You can also look for information at:
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-Connection>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/AnyEvent-Connection>
- CPAN Ratings
<http://cpanratings.perl.org/d/AnyEvent-Connection>
- Search CPAN
<http://search.cpan.org/dist/AnyEvent-Connection/>
π§ ACKNOWLEDGEMENTS π§
(this section is literally empty in the original, and we respect that. the silence is the acknowledgement. very main character energy β¨)
π COPYRIGHT & LICENSE π
Copyright 2009 Mons Anderson, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π and that's the whole page, bestie β this was perl v5.34.0, dated 2022-06-05, from the man page AnyEve...ection(3pm). go connect to something. ily. ππ¦πΈ
π¦ where this page comes from
- debian bookworm: libanyevent-connection-perl 0.06-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libanyevent-connection-perl 0.06-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libanyevent-connection-perl 0.06-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libanyevent-connection-perl 0.06-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libanyevent-connection-perl 0.06-6 Β· 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