1 | #!/usr/bin/perl |
1 | #!/usr/bin/perl |
2 | |
2 | |
3 | # this crap is an asynchroneous finger client. it's rather idiotic ;) |
3 | # this crap is an asynchronous finger client. it's rather idiotic ;) |
4 | |
4 | |
5 | use Coro; |
5 | use Coro; |
6 | use Coro::Event; |
6 | use Coro::Event; |
7 | use Coro::Socket; |
7 | use Coro::Socket; |
8 | |
8 | |
… | |
… | |
10 | sub finger { |
10 | sub finger { |
11 | my $user = shift; |
11 | my $user = shift; |
12 | my $host = shift; |
12 | my $host = shift; |
13 | |
13 | |
14 | my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger" |
14 | my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger" |
15 | or die; |
15 | or die "$user\@$host: $!"; |
16 | |
16 | |
17 | print $fh "$user\n"; |
17 | print $fh "$user\n"; |
18 | |
18 | |
19 | print "$user\@$host: $_" while <$fh>; |
19 | print "$user\@$host: $_" while <$fh>; |
20 | print "$user\@$host: done\n"; |
20 | print "$user\@$host: done\n"; |
… | |
… | |
38 | print "unknown command '$cmd', either 'finger' or 'quit'\n"; |
38 | print "unknown command '$cmd', either 'finger' or 'quit'\n"; |
39 | } |
39 | } |
40 | } |
40 | } |
41 | } |
41 | } |
42 | |
42 | |
|
|
43 | async { finger("root", "localhost") }; |
|
|
44 | |
43 | # display the time or garble the display, YMMV. |
45 | # display the time or garble the display, YMMV. |
44 | sub timer : Coro { |
46 | sub timer : Coro { |
45 | my $w = Coro::Event->timer(interval => 0.001, hard => 1); |
47 | my $w = Coro::Event->timer(interval => 0.001, hard => 1); |
46 | use Time::HiRes qw(time); |
48 | use Time::HiRes qw(time); |
47 | while () { |
49 | while () { |
48 | $w->next; |
50 | $w->next; |
49 | print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8"; |
51 | print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8"; |
50 | }; |
52 | }; |
51 | } |
53 | } |
52 | |
54 | |
|
|
55 | cede; # make sure the watchers are installed |
53 | print "unlooped with value: ",loop(),"\n"; |
56 | print "unlooped with value: ",loop(),"\n"; |
54 | |
57 | |