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

Comparing Coro/eg/event (file contents):
Revision 1.1 by root, Sun Jul 15 02:36:54 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
3# useless stuff
2 4
3use Coro; 5use Coro;
4use Coro::Event; 6use Coro::Event;
5 7
6sub keyboard : Coro {
7 my $w = Coro::Event->io(fd => *STDIN, poll => 'r'); 8my $stdin = Coro::Event->io(fd => \*STDIN, poll => 'r');
8 while() { 9
9 print "cmd> "; 10# this gets started everytime a user enters a finger command
10 my $ev = $w->next; my $cmd = <STDIN>; 11sub finger {
11 print "data> "; 12 my $user = shift;
12 my $ev = $w->next; my $data = <STDIN>; 13 my $host = shift;
13 } 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 $io or die;
19 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;
14} 25}
15 26
27# this reads one line from the keyboard
28sub kbdline {
29 $stdin->next;
30 my $x = <STDIN>; chomp $x; $x;
31}
32
33# this is the main task
34sub keyboard : Coro {
35 $|=1;
36 while() {
37 print "cmd> "; my $cmd = kbdline;
38 if ($cmd eq "finger") {
39 print "user> "; my $user = kbdline;
40 print "host> "; my $host = kbdline;
41 async { finger(@_) } $user, $host;
42 } elsif ($cmd eq "quit") {
43 unloop(777);
44 terminate;
45 } else {
46 print "enter command, either 'finger' or 'quit'\n";
47 }
48 }
49}
50
51# display the time or garble the display, YMMV.
52sub timer : Coro {
53 my $w = Coro::Event->timer(interval => 0.001, hard => 1);
54 use Time::HiRes qw(time);
55 while () {
56 $w->next;
57 print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8";
58 };
59}
60
61print "unlooped with value: ",loop(),"\n";
62

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines