ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/event
Revision: 1.6
Committed: Tue Jul 17 02:21:56 2001 UTC (22 years, 11 months ago) by root
Branch: MAIN
Changes since 1.5: +7 -12 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3 root 1.6 # useless stuff
4 root 1.5
5 root 1.1 use Coro;
6     use Coro::Event;
7    
8 root 1.2 my $stdin = Coro::Event->io(fd => \*STDIN, poll => 'r');
9    
10 root 1.6 # this gets started everytime a user enters a finger command
11 root 1.4 sub finger {
12 root 1.6 my $user = shift;
13 root 1.4 my $host = shift;
14     use IO::Socket::INET;
15     # is there ANY way to do non-blocking connects with IO::Socket::INET?
16     # I don't see how...
17     my $io = new IO::Socket::INET PeerAddr => "$host:finger";
18 root 1.5 $io or die;
19 root 1.4 syswrite $io, "$user\n";
20     my $r = Coro::Event->io(fd => $io, poll => 'r');
21     my $buf;
22     $r->next while 0 != sysread $io, $buf, 8192, length $buf;
23     #do_timer(after => 5);
24     print $buf;
25     }
26    
27 root 1.6 # this reads one line from the keyboard
28 root 1.2 sub kbdline {
29     $stdin->next;
30     my $x = <STDIN>; chomp $x; $x;
31     }
32    
33 root 1.6 # this is the main task
34 root 1.1 sub keyboard : Coro {
35 root 1.2 $|=1;
36     while() {
37     print "cmd> "; my $cmd = kbdline;
38 root 1.4 if ($cmd eq "finger") {
39     print "user> "; my $user = kbdline;
40     print "host> "; my $host = kbdline;
41 root 1.5 async { finger(@_) } $user, $host;
42 root 1.4 } elsif ($cmd eq "quit") {
43     unloop(777);
44     terminate;
45     } else {
46     print "enter command, either 'finger' or 'quit'\n";
47     }
48 root 1.2 }
49     }
50    
51 root 1.6 # display the time or garble the display, YMMV.
52 root 1.4 sub timer : Coro {
53 root 1.5 my $w = Coro::Event->timer(interval => 0.001, hard => 1);
54 root 1.4 use Time::HiRes qw(time);
55 root 1.2 while () {
56     $w->next;
57 root 1.6 print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8";
58 root 1.2 };
59 root 1.1 }
60 root 1.2
61 root 1.4 print "unlooped with value: ",loop(),"\n";
62 root 1.1