ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/event
(Generate patch)

Comparing Coro/eg/event (file contents):
Revision 1.5 by root, Tue Jul 17 00:24:15 2001 UTC vs.
Revision 1.6 by root, Tue Jul 17 02:21:56 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines