ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/event
Revision: 1.5
Committed: Tue Jul 17 00:24:15 2001 UTC (22 years, 11 months ago) by root
Branch: MAIN
Changes since 1.4: +13 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3 root 1.5 <<EOF;
4     finger
5     localhost
6     root
7     finger
8     localhost
9     root
10     EOF
11    
12 root 1.1 use Coro;
13     use Coro::Event;
14    
15 root 1.5 #$Event::DebugLevel = 4;
16 root 1.4
17 root 1.2 my $stdin = Coro::Event->io(fd => \*STDIN, poll => 'r');
18    
19 root 1.4 sub finger {
20     my $host = shift;
21     my $user = shift;
22     use IO::Socket::INET;
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 root 1.5 $io or die;
27 root 1.4 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;
33     }
34    
35 root 1.2 sub kbdline {
36     $stdin->next;
37     my $x = <STDIN>; chomp $x; $x;
38     }
39    
40 root 1.1 sub keyboard : Coro {
41 root 1.2 $|=1;
42     while() {
43     print "cmd> "; my $cmd = kbdline;
44 root 1.4 if ($cmd eq "finger") {
45     print "user> "; my $user = kbdline;
46     print "host> "; my $host = kbdline;
47 root 1.5 async { finger(@_) } $user, $host;
48 root 1.4 } elsif ($cmd eq "quit") {
49     unloop(777);
50     terminate;
51     } else {
52     print "enter command, either 'finger' or 'quit'\n";
53     }
54 root 1.2 }
55     }
56    
57 root 1.4 sub timer : Coro {
58 root 1.5 my $w = Coro::Event->timer(interval => 0.001, hard => 1);
59 root 1.4 use Time::HiRes qw(time);
60 root 1.2 while () {
61     $w->next;
62 root 1.4 print "\e7\e[A\10\10\10 <time ",time,"> \e8";
63 root 1.2 };
64 root 1.1 }
65 root 1.2
66 root 1.4 print "unlooped with value: ",loop(),"\n";
67 root 1.1