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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines