AnyEve...ection(3pm)

πŸ“¦
version 0.06 Β· 2 versions
  • 0.06 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.06 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ¦‹ 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 the connfail = sub line 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 disconnects
  • error β€” fires in error conditions for callbackless methods, like fr fr when you call push_write on a client that isn't connected πŸ’€

πŸ’– OPTIONS πŸ’–

  • host β€” the host to connect to
  • port β€” the port to connect to
  • timeout [ = 3 ] β€” connect/read/write timeout, measured in seconds ⏱️
  • reconnect [ = 1 ] β€” if it's true, automatically reconnect after a disconnect/connfail, after a delay of $reconnect seconds
  • rawcon [ = 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 goooo
  • disconnect ($reason) β€” close the current connection. reason is optional, no pressure
  • reconnect β€” close the current connection and establish a brand new one πŸ¦‹
  • after($interval, $cb->()) β€” helper method. It's AE::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's AE::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 β€” see AE::Handle::push_write
  • push_read β€” see AE::Handle::push_read
  • unshift_read β€” see AE::Handle::unshift_read
  • say β€” same as push_write + a newline
  • reply β€” same as push_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 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