1 |
#!/usr/bin/perl |
2 |
|
3 |
# this crap is an asynchroneous finger client. it's rather idiotic ;) |
4 |
|
5 |
use Coro; |
6 |
use Coro::Event; |
7 |
use Coro::Socket; |
8 |
|
9 |
# this gets started everytime a user enters a finger command |
10 |
sub finger { |
11 |
my $user = shift; |
12 |
my $host = shift; |
13 |
|
14 |
my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger" |
15 |
or die "$user\@$host: $!"; |
16 |
|
17 |
print $fh "$user\n"; |
18 |
|
19 |
print "$user\@$host: $_" while <$fh>; |
20 |
print "$user\@$host: done\n"; |
21 |
} |
22 |
|
23 |
my $stdin = new_from_fh Coro::Handle \*STDIN; |
24 |
|
25 |
# this is the main task |
26 |
sub keyboard : Coro { |
27 |
$|=1; |
28 |
while() { |
29 |
print "cmd> "; my $cmd = <$stdin>; chomp $cmd; |
30 |
if ($cmd eq "finger") { |
31 |
print "user> "; my $user = <$stdin>; chomp $user; |
32 |
print "host> "; my $host = <$stdin>; chomp $host; |
33 |
async { finger($user, $host) }; |
34 |
} elsif ($cmd eq "quit") { |
35 |
unloop(777); |
36 |
terminate; |
37 |
} else { |
38 |
print "unknown command '$cmd', either 'finger' or 'quit'\n"; |
39 |
} |
40 |
} |
41 |
} |
42 |
|
43 |
async { finger("root", "localhost") }; |
44 |
|
45 |
# display the time or garble the display, YMMV. |
46 |
sub timer : Coro { |
47 |
my $w = Coro::Event->timer(interval => 0.001, hard => 1); |
48 |
use Time::HiRes qw(time); |
49 |
while () { |
50 |
$w->next; |
51 |
print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8"; |
52 |
}; |
53 |
} |
54 |
|
55 |
print "unlooped with value: ",loop(),"\n"; |
56 |
|