1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
NAME
AnyEvent::Connection - Base class for tcp connectful clients
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;
EVENTS
connected ($connobject, $host, $port)
Called when client get connected.
connfail
Called, when client fails to connect
disconnect
Called whenever client disconnects
error
Called in error conditions for callbackless methods (for ex: when
calling push_write on non-connected client)
OPTIONS
host
Host to connect to
port
Port to connect to
timeout [ = 3 ]
Connect/read/write timeout in seconds
reconnect [ = 1 ]
If true, automatically reconnect after disconnect/connfail after
delay $reconnect seconds
rawcon [ = AnyEvent::Connection::Raw ]
Class that implements low-level connection
OPERATION METHODS
new Cleates connection object (see OPTIONS)
connect
Begin connection
disconnect ($reason)
Close current connection. reason is optional
reconnect
Close current connection and establish a new one
after($interval, $cb->())
Helper method. AE::timer(after), associated with current connection
Will be destroyed if connection is destroyed, so no timer invocation
after connection destruction.
periodic($interval, $cb->())
Helper method. AE::timer(periodic), associated with current
connection
Will be destroyed if connection is destroyed, so no timer invocation
after connection destruction.
periodic_stop()
If called within periodic callback, periodic will be stopped.
my $count;
$client->periodic(1,sub {
$client->periodic_stop if ++$count > 10;
});
# callback will be called only 10 times;
destroy
Close connection, destroy all associated objects and timers, clean
self
CONNECT METHODS
When connected, there are some methods, that proxied to raw connection
or to AE::Handle
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 + newline
reply
Same as push_write + newline
For next methods there is a feature. Callback will be called in any way,
either by successful processing or by error or object destruction
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.
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
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.
|