… | |
… | |
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 | warn "got error $msg\n"; |
16 | AE::log warn => "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 | warn "got line <$line>\n"; |
27 | AE::log warn => "got line <$line>\n"; |
28 | $cv->send; |
28 | $cv->send; |
29 | }); |
29 | }); |
30 | |
30 | |
31 | $cv->recv; |
31 | $cv->recv; |
32 | |
32 | |
… | |
… | |
1432 | data. |
1432 | data. |
1433 | |
1433 | |
1434 | Example: read 2 bytes. |
1434 | Example: read 2 bytes. |
1435 | |
1435 | |
1436 | $handle->push_read (chunk => 2, sub { |
1436 | $handle->push_read (chunk => 2, sub { |
1437 | warn "yay ", unpack "H*", $_[1]; |
1437 | AE::log debug => "yay " . unpack "H*", $_[1]; |
1438 | }); |
1438 | }); |
1439 | |
1439 | |
1440 | =cut |
1440 | =cut |
1441 | |
1441 | |
1442 | register_read_type chunk => sub { |
1442 | register_read_type chunk => sub { |
… | |
… | |
2330 | C<low_water_mark> this will be called precisely when all data has been |
2330 | C<low_water_mark> this will be called precisely when all data has been |
2331 | written to the socket: |
2331 | written to the socket: |
2332 | |
2332 | |
2333 | $handle->push_write (...); |
2333 | $handle->push_write (...); |
2334 | $handle->on_drain (sub { |
2334 | $handle->on_drain (sub { |
2335 | warn "all data submitted to the kernel\n"; |
2335 | AE::log debug => "all data submitted to the kernel\n"; |
2336 | undef $handle; |
2336 | undef $handle; |
2337 | }); |
2337 | }); |
2338 | |
2338 | |
2339 | If you just want to queue some data and then signal EOF to the other side, |
2339 | If you just want to queue some data and then signal EOF to the other side, |
2340 | consider using C<< ->push_shutdown >> instead. |
2340 | consider using C<< ->push_shutdown >> instead. |