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.223 by root, Thu Sep 1 04:07:18 2011 UTC vs.
Revision 1.227 by root, Tue Jan 10 13:32:23 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
1081=cut 1081=cut
1082 1082
1083register_write_type storable => sub { 1083register_write_type storable => sub {
1084 my ($self, $ref) = @_; 1084 my ($self, $ref) = @_;
1085 1085
1086 require Storable; 1086 require Storable unless $Storable::VERSION;
1087 1087
1088 pack "w/a*", Storable::nfreeze ($ref) 1088 pack "w/a*", Storable::nfreeze ($ref)
1089}; 1089};
1090 1090
1091=back 1091=back
1432data. 1432data.
1433 1433
1434Example: read 2 bytes. 1434Example: read 2 bytes.
1435 1435
1436 $handle->push_read (chunk => 2, sub { 1436 $handle->push_read (chunk => 2, sub {
1437 AE::log debug => "yay " . unpack "H*", $_[1]; 1437 say "yay " . unpack "H*", $_[1];
1438 }); 1438 });
1439 1439
1440=cut 1440=cut
1441 1441
1442register_read_type chunk => sub { 1442register_read_type chunk => sub {
1476 if (@_ < 3) { 1476 if (@_ < 3) {
1477 # this is more than twice as fast as the generic code below 1477 # this is more than twice as fast as the generic code below
1478 sub { 1478 sub {
1479 $_[0]{rbuf} =~ s/^([^\015\012]*)(\015?\012)// or return; 1479 $_[0]{rbuf} =~ s/^([^\015\012]*)(\015?\012)// or return;
1480 1480
1481 $cb->($_[0], $1, $2); 1481 $cb->($_[0], "$1", "$2");
1482 1 1482 1
1483 } 1483 }
1484 } else { 1484 } else {
1485 $eol = quotemeta $eol unless ref $eol; 1485 $eol = quotemeta $eol unless ref $eol;
1486 $eol = qr|^(.*?)($eol)|s; 1486 $eol = qr|^(.*?)($eol)|s;
1487 1487
1488 sub { 1488 sub {
1489 $_[0]{rbuf} =~ s/$eol// or return; 1489 $_[0]{rbuf} =~ s/$eol// or return;
1490 1490
1491 $cb->($_[0], $1, $2); 1491 $cb->($_[0], "$1", "$2");
1492 1 1492 1
1493 } 1493 }
1494 } 1494 }
1495}; 1495};
1496 1496
1711=cut 1711=cut
1712 1712
1713register_read_type storable => sub { 1713register_read_type storable => sub {
1714 my ($self, $cb) = @_; 1714 my ($self, $cb) = @_;
1715 1715
1716 require Storable; 1716 require Storable unless $Storable::VERSION;
1717 1717
1718 sub { 1718 sub {
1719 # when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method 1719 # when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method
1720 defined (my $len = eval { unpack "w", $_[0]{rbuf} }) 1720 defined (my $len = eval { unpack "w", $_[0]{rbuf} })
1721 or return; 1721 or return;
1792some readings of the the SSL/TLS specifications basically require this 1792some readings of the the SSL/TLS specifications basically require this
1793attack to be working, as SSL/TLS implementations might stall sending data 1793attack to be working, as SSL/TLS implementations might stall sending data
1794during a rehandshake. 1794during a rehandshake.
1795 1795
1796As a guideline, during the initial handshake, you should not stop reading, 1796As a guideline, during the initial handshake, you should not stop reading,
1797and as a client, it might cause problems, depending on your applciation. 1797and as a client, it might cause problems, depending on your application.
1798 1798
1799=cut 1799=cut
1800 1800
1801sub stop_read { 1801sub stop_read {
1802 my ($self) = @_; 1802 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines