ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.224 by root, Mon Sep 5 07:21:54 2011 UTC vs.
Revision 1.228 by root, Mon Feb 6 00:17:26 2012 UTC

11 11
12 my $hdl; $hdl = new AnyEvent::Handle 12 my $hdl; $hdl = new AnyEvent::Handle
13 fh => \*STDIN, 13 fh => \*STDIN,
14 on_error => sub { 14 on_error => sub {
15 my ($hdl, $fatal, $msg) = @_; 15 my ($hdl, $fatal, $msg) = @_;
16 AE::log warn => "got error $msg\n"; 16 AE::log error => "got error $msg\n";
17 $hdl->destroy; 17 $hdl->destroy;
18 $cv->send; 18 $cv->send;
19 }; 19 };
20 20
21 # send some request line 21 # send some request line
22 $hdl->push_write ("getinfo\015\012"); 22 $hdl->push_write ("getinfo\015\012");
23 23
24 # read the response line 24 # read the response line
25 $hdl->push_read (line => sub { 25 $hdl->push_read (line => sub {
26 my ($hdl, $line) = @_; 26 my ($hdl, $line) = @_;
27 AE::log warn => "got line <$line>\n"; 27 say "got line <$line>";
28 $cv->send; 28 $cv->send;
29 }); 29 });
30 30
31 $cv->recv; 31 $cv->recv;
32 32
128=item on_connect => $cb->($handle, $host, $port, $retry->()) 128=item on_connect => $cb->($handle, $host, $port, $retry->())
129 129
130This callback is called when a connection has been successfully established. 130This callback is called when a connection has been successfully established.
131 131
132The peer's numeric host and port (the socket peername) are passed as 132The peer's numeric host and port (the socket peername) are passed as
133parameters, together with a retry callback. 133parameters, together with a retry callback. At the time it is called the
134read and write queues, EOF status, TLS status and similar properties of
135the handle will have been reset.
134 136
137It is not allowed to use the read or write queues while the handle object
138is connecting.
139
135If, for some reason, the handle is not acceptable, calling C<$retry> 140If, for some reason, the handle is not acceptable, calling C<$retry> will
136will continue with the next connection target (in case of multi-homed 141continue with the next connection target (in case of multi-homed hosts or
137hosts or SRV records there can be multiple connection endpoints). At the 142SRV records there can be multiple connection endpoints). The C<$retry>
138time it is called the read and write queues, eof status, tls status and 143callback can be invoked after the connect callback returns, i.e. one can
139similar properties of the handle will have been reset. 144start a handshake and then decide to retry with the next host if the
145handshake fails.
140 146
141In most cases, you should ignore the C<$retry> parameter. 147In most cases, you should ignore the C<$retry> parameter.
142 148
143=item on_connect_error => $cb->($handle, $message) 149=item on_connect_error => $cb->($handle, $message)
144 150
1432data. 1438data.
1433 1439
1434Example: read 2 bytes. 1440Example: read 2 bytes.
1435 1441
1436 $handle->push_read (chunk => 2, sub { 1442 $handle->push_read (chunk => 2, sub {
1437 AE::log debug => "yay " . unpack "H*", $_[1]; 1443 say "yay " . unpack "H*", $_[1];
1438 }); 1444 });
1439 1445
1440=cut 1446=cut
1441 1447
1442register_read_type chunk => sub { 1448register_read_type chunk => sub {
1476 if (@_ < 3) { 1482 if (@_ < 3) {
1477 # this is more than twice as fast as the generic code below 1483 # this is more than twice as fast as the generic code below
1478 sub { 1484 sub {
1479 $_[0]{rbuf} =~ s/^([^\015\012]*)(\015?\012)// or return; 1485 $_[0]{rbuf} =~ s/^([^\015\012]*)(\015?\012)// or return;
1480 1486
1481 $cb->($_[0], $1, $2); 1487 $cb->($_[0], "$1", "$2");
1482 1 1488 1
1483 } 1489 }
1484 } else { 1490 } else {
1485 $eol = quotemeta $eol unless ref $eol; 1491 $eol = quotemeta $eol unless ref $eol;
1486 $eol = qr|^(.*?)($eol)|s; 1492 $eol = qr|^(.*?)($eol)|s;
1487 1493
1488 sub { 1494 sub {
1489 $_[0]{rbuf} =~ s/$eol// or return; 1495 $_[0]{rbuf} =~ s/$eol// or return;
1490 1496
1491 $cb->($_[0], $1, $2); 1497 $cb->($_[0], "$1", "$2");
1492 1 1498 1
1493 } 1499 }
1494 } 1500 }
1495}; 1501};
1496 1502
1792some readings of the the SSL/TLS specifications basically require this 1798some readings of the the SSL/TLS specifications basically require this
1793attack to be working, as SSL/TLS implementations might stall sending data 1799attack to be working, as SSL/TLS implementations might stall sending data
1794during a rehandshake. 1800during a rehandshake.
1795 1801
1796As a guideline, during the initial handshake, you should not stop reading, 1802As a guideline, during the initial handshake, you should not stop reading,
1797and as a client, it might cause problems, depending on your applciation. 1803and as a client, it might cause problems, depending on your application.
1798 1804
1799=cut 1805=cut
1800 1806
1801sub stop_read { 1807sub stop_read {
1802 my ($self) = @_; 1808 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines