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.7 by root, Tue Jul 24 20:18:12 2001 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2
3# this crap is an asynchroneous finger client. it's rather idiotic ;)
2 4
3use Coro; 5use Coro;
4use Coro::Event; 6use Coro::Event;
7use Coro::Socket;
5 8
6sub keyboard : Coro { 9# this gets started everytime a user enters a finger command
7 my $w = Coro::Event->io(fd => *STDIN, poll => 'r'); 10sub finger {
8 while() { 11 my $user = shift;
9 print "cmd> "; 12 my $host = shift;
10 my $ev = $w->next; my $cmd = <STDIN>; 13
11 print "data> "; 14 my $fh = new_inet Coro::Socket PeerHost => $host, PeerPort => "finger"
12 my $ev = $w->next; my $data = <STDIN>; 15 or die;
13 } 16
17 print $fh "$user\n";
18
19 print "$user\@$host: $_" while <$fh>;
20 print "$user\@$host: done\n";
14} 21}
15 22
23my $stdin = new_from_fh Coro::Handle \*STDIN;
24
25# this is the main task
26sub keyboard : Coro {
27 $|=1;
28 while() {
29 print "cmd> "; my $cmd = <$stdin>; chomp $cmd;
30 if ($cmd eq "finger") {
31 print "user> "; my $user = <$stdin>; chomp $user;
32 print "host> "; my $host = <$stdin>; chomp $host;
33 async { finger($user, $host) };
34 } elsif ($cmd eq "quit") {
35 unloop(777);
36 terminate;
37 } else {
38 print "unknown command '$cmd', either 'finger' or 'quit'\n";
39 }
40 }
41}
42
43# display the time or garble the display, YMMV.
44sub timer : Coro {
45 my $w = Coro::Event->timer(interval => 0.001, hard => 1);
46 use Time::HiRes qw(time);
47 while () {
48 $w->next;
49 print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8";
50 };
51}
52
53print "unlooped with value: ",loop(),"\n";
54

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines