… | |
… | |
9 | AnyEvent offers a lot of support you can use. |
9 | AnyEvent offers a lot of support you can use. |
10 | |
10 | |
11 | |
11 | |
12 | =head1 What is AnyEvent? |
12 | =head1 What is AnyEvent? |
13 | |
13 | |
14 | Skip this section if you want to see code, now! |
14 | If you don't care for the "why's" and want to see code, skip this section! |
15 | |
15 | |
16 | AnyEvent is first of all just a framework to do event-based |
16 | AnyEvent is first of all just a framework to do event-based |
17 | programming. Typically such frameworks are an all-or-nothing thing: If you |
17 | programming. Typically such frameworks are an all-or-nothing thing: If you |
18 | use one such framework, you can't (easily, or even at all) use another in |
18 | use one such framework, you can't (easily, or even at all) use another in |
19 | the same program. |
19 | the same program. |
… | |
… | |
480 | # use a condvar to return results |
480 | # use a condvar to return results |
481 | my $cv = AnyEvent->condvar; |
481 | my $cv = AnyEvent->condvar; |
482 | |
482 | |
483 | # first, connect to the host |
483 | # first, connect to the host |
484 | tcp_connect $host, "finger", sub { |
484 | tcp_connect $host, "finger", sub { |
485 | # the callback gets the socket handle - or nothing |
485 | # the callback receives the socket handle - or nothing |
486 | my ($fh) = @_ |
486 | my ($fh) = @_ |
487 | or return $cv->send; |
487 | or return $cv->send; |
488 | |
488 | |
489 | # now write the username |
489 | # now write the username |
490 | syswrite $fh, "$user\015\012"; |
490 | syswrite $fh, "$user\015\012"; |