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.5 by root, Tue Jul 17 00:24:15 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines