.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "AnyEvent::Connection 3pm" .TH AnyEvent::Connection 3pm "2017-06-22" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" AnyEvent::Connection \- Base class for tcp connectful clients .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package MyTCPClient; \& use base \*(AqAnyEvent::Connection\*(Aq; \& \& package main; \& my $client = MyTCPClient\->new( \& host => \*(Aqlocalhost\*(Aq, \& 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; .Ve .SH "EVENTS" .IX Header "EVENTS" .ie n .IP "connected ($connobject, $host, $port)" 4 .el .IP "connected ($connobject, \f(CW$host\fR, \f(CW$port\fR)" 4 .IX Item "connected ($connobject, $host, $port)" Called when client get connected. .IP "connfail" 4 .IX Item "connfail" Called, when client fails to connect .IP "disconnect" 4 .IX Item "disconnect" Called whenever client disconnects .IP "error" 4 .IX Item "error" Called in error conditions for callbackless methods (for ex: when calling push_write on non-connected client) .SH "OPTIONS" .IX Header "OPTIONS" .IP "host" 4 .IX Item "host" Host to connect to .IP "port" 4 .IX Item "port" Port to connect to .IP "timeout [ = 3 ]" 4 .IX Item "timeout [ = 3 ]" Connect/read/write timeout in seconds .IP "reconnect [ = 1 ]" 4 .IX Item "reconnect [ = 1 ]" If true, automatically reconnect after disconnect/connfail after delay \f(CW$reconnect\fR seconds .IP "rawcon [ = AnyEvent::Connection::Raw ]" 4 .IX Item "rawcon [ = AnyEvent::Connection::Raw ]" Class that implements low-level connection .SH "OPERATION METHODS" .IX Header "OPERATION METHODS" .IP "new" 4 .IX Item "new" Cleates connection object (see \s-1OPTIONS\s0) .IP "connect" 4 .IX Item "connect" Begin connection .IP "disconnect ($reason)" 4 .IX Item "disconnect ($reason)" Close current connection. reason is optional .IP "reconnect" 4 .IX Item "reconnect" Close current connection and establish a new one .ie n .IP "after($interval, $cb\->())" 4 .el .IP "after($interval, \f(CW$cb\fR\->())" 4 .IX Item "after($interval, $cb->())" Helper method. AE::timer(after), associated with current connection .Sp Will be destroyed if connection is destroyed, so no timer invocation after connection destruction. .ie n .IP "periodic($interval, $cb\->())" 4 .el .IP "periodic($interval, \f(CW$cb\fR\->())" 4 .IX Item "periodic($interval, $cb->())" Helper method. AE::timer(periodic), associated with current connection .Sp Will be destroyed if connection is destroyed, so no timer invocation after connection destruction. .IP "\fIperiodic_stop()\fR" 4 .IX Item "periodic_stop()" If called within periodic callback, periodic will be stopped. .Sp .Vb 4 \& my $count; \& $client\->periodic(1,sub { \& $client\->periodic_stop if ++$count > 10; \& }); \& \& # callback will be called only 10 times; .Ve .IP "destroy" 4 .IX Item "destroy" Close connection, destroy all associated objects and timers, clean self .SH "CONNECT METHODS" .IX Header "CONNECT METHODS" When connected, there are some methods, that proxied to raw connection or to AE::Handle .IP "push_write" 4 .IX Item "push_write" See AE::Handle::push_write .IP "push_read" 4 .IX Item "push_read" See AE::Handle::push_read .IP "unshift_read" 4 .IX Item "unshift_read" See AE::Handle::unshift_read .IP "say" 4 .IX Item "say" Same as push_write + newline .IP "reply" 4 .IX Item "reply" Same as push_write + newline .PP For next methods there is a feature. Callback will be called in any way, either by successful processing or by error or object destruction .ie n .IP "recv($bytes, %args, cb => $cb\->())" 4 .el .IP "recv($bytes, \f(CW%args\fR, cb => \f(CW$cb\fR\->())" 4 .IX Item "recv($bytes, %args, cb => $cb->())" Similar to .Sp .Vb 1 \& $fh\->push_read(chunk => $bytes, $cb\->()); .Ve .ie n .IP "command($data, %args, cb => $cb\->());" 4 .el .IP "command($data, \f(CW%args\fR, cb => \f(CW$cb\fR\->());" 4 .IX Item "command($data, %args, cb => $cb->());" Similar to .Sp .Vb 2 \& $fh\->push_write($data); \& $fh\->push_read(line => $cb\->()); .Ve .SH "AUTHOR" .IX Header "AUTHOR" Mons Anderson, \f(CW\*(C`\*(C'\fR .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \f(CW\*(C`bug\-anyevent\-connection at rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc AnyEvent::Connection .Ve .PP You can also look for information at: .IP "\(bu" 4 \&\s-1RT: CPAN\s0's request tracker .Sp .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2009 Mons Anderson, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.