AnyEvent-Connection
view release on metacpan or search on metacpan
lib/AnyEvent/Connection.pm view on Meta::CPAN
package AnyEvent::Connection;
use common::sense 2;m{
use strict;
use warnings;
};
use Object::Event 1.21;
use base 'Object::Event';
use AnyEvent 5;
use AnyEvent::Socket;
use Carp;
use Scalar::Util qw(weaken);
use AnyEvent::Connection::Raw;
use AnyEvent::Connection::Util;
# @rewrite s/^# //; # Development hacks, see L<Devel::Rewrite>
# use Devel::Leak::Cb;
=head1 NAME
AnyEvent::Connection - Base class for tcp connectful clients
=cut
our $VERSION = '0.06';
=head1 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;
=head1 EVENTS
=over 4
=item connected ($connobject, $host, $port)
Called when client get connected.
=item connfail
Called, when client fails to connect
=item disconnect
Called whenever client disconnects
=item error
Called in error conditions for callbackless methods (for ex: when calling push_write on non-connected client)
=back
=head1 OPTIONS
=over 4
=item host
Host to connect to
=item port
Port to connect to
=item timeout [ = 3 ]
Connect/read/write timeout in seconds
=item reconnect [ = 1 ]
If true, automatically reconnect after disconnect/connfail after delay $reconnect seconds
=item rawcon [ = AnyEvent::Connection::Raw ]
( run in 1.242 second using v1.01-cache-2.11-cpan-df04353d9ac )