ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.4
Committed: Sat May 3 12:17:35 2008 UTC (16 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_41, rel-3_5, rel-3_4
Changes since 1.3: +28 -26 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 #!perl
2 root 1.3
3 elmex 1.1 use strict;
4 root 1.3 use AnyEvent::Impl::Perl;
5 elmex 1.1 use AnyEvent::Handle;
6 root 1.4 use Test::More tests => 3;
7 elmex 1.1 use Socket;
8    
9 elmex 1.2 {
10     my $cv = AnyEvent->condvar;
11 elmex 1.1
12 elmex 1.2 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
13 elmex 1.1
14 root 1.4 my $rd_ae = AnyEvent::Handle->new (
15     fh => $rd,
16     on_eof => sub { $cv->broadcast },
17     );
18    
19 elmex 1.2 my $concat;
20 elmex 1.1
21 root 1.4 $rd_ae->push_read_line (sub {
22     is ($_[1], "A", 'A line was read correctly');
23     my $cb; $cb = sub {
24     $concat .= $_[1];
25     $_[0]->push_read_line ($cb);
26     };
27     $_[0]->push_read_line ($cb);
28 elmex 1.2 });
29    
30 root 1.4 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n";
31     close $wr;
32 elmex 1.2
33     $cv->wait;
34 root 1.4 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly');
35 elmex 1.2 }
36    
37     {
38     my $cv = AnyEvent->condvar;
39    
40     socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
41    
42     my $concat;
43    
44     my $rd_ae =
45     AnyEvent::Handle->new (
46 root 1.4 fh => $rd,
47     on_eof => sub { $cv->broadcast },
48     on_read => sub {
49     $_[0]->push_read_line (sub {
50     $concat .= "$_[1]:";
51     });
52 elmex 1.2 }
53     );
54    
55 root 1.4 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
56    
57     $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
58     undef $wr;
59     undef $wr_ae;
60 elmex 1.1
61 elmex 1.2 $cv->wait;
62 elmex 1.1
63 root 1.4 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
64 elmex 1.2 }