ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/eg/handle
Revision: 1.2
Committed: Thu May 15 08:37:55 2008 UTC (16 years, 1 month ago) by elmex
Branch: MAIN
CVS Tags: rel-4_0, rel-3_5
Changes since 1.1: +0 -1 lines
Log Message:
implemented non-blocking connects in a different manner than ::Socket.

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/bin/perl
2     # This small example script shows how to do non-blocking
3     # reads from a file handle.
4    
5     use AnyEvent::Handle;
6     my $cv = AnyEvent->condvar;
7    
8     my $ae_fh =
9     AnyEvent::Handle->new (
10     fh => \*STDIN,
11     on_eof => sub { $cv->broadcast }
12     );
13    
14     $ae_fh->push_read_line (sub {
15     my ($ae_fh, $line) = @_;
16     print "Got line [$line]\n";
17    
18     $ae_fh->push_read (sub {
19     my ($ae_fh) = @_;
20     print "Got additional data:[\n".$ae_fh->rbuf."]\n";
21    
22     if ($ae_fh->rbuf =~ s/^.*\bend\b//s) {
23     print "'end' detected, stopping program\n";
24     $cv->broadcast;
25     return 1;
26     }
27    
28     return 0;
29     });
30     });
31    
32     $cv->wait;