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

Comparing Coro/eg/event (file contents):
Revision 1.3 by root, Sun Jul 15 15:58:16 2001 UTC vs.
Revision 1.4 by root, Sun Jul 15 22:19:49 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines