ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/event
Revision: 1.10
Committed: Mon Nov 6 19:40:02 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_5, rel-3_41, rel-3_55, rel-3_51, rel-3_4, rel-3_1, rel-3_5, rel-3_3, rel-3_2, rel-3_0, rel-3_01, rel-3_11, stack_sharing, rel-3_501
Changes since 1.9: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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