ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/event
Revision: 1.3
Committed: Sun Jul 15 15:58:16 2001 UTC (22 years, 11 months ago) by root
Branch: MAIN
Changes since 1.2: +14 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3     use Coro;
4     use Coro::Event;
5    
6 root 1.2 my $stdin = Coro::Event->io(fd => \*STDIN, poll => 'r');
7    
8     sub kbdline {
9     $stdin->next;
10     my $x = <STDIN>; chomp $x; $x;
11     }
12    
13 root 1.1 sub keyboard : Coro {
14 root 1.2 $|=1;
15     while() {
16     print "cmd> "; my $cmd = kbdline;
17     print "data> "; my $data = kbdline;
18     print "cmd<$cmd> data<$data>\n";
19     print "working...";
20     do_timer(after => 1);
21     print "done\n";
22     }
23     }
24    
25     sub idle : Coro {
26     my $w = Coro::Event->idle(min => 1, max => 2);
27     while () {
28     $w->next;
29     print ".";
30     };
31 root 1.1 }
32 root 1.2
33 root 1.3 sub finger : Coro {
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    
47 root 1.2 Coro::Event->main;
48 root 1.1