ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.7
Committed: Sat May 24 23:15:14 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_04, rel-4_14, rel-4_13, rel-4_05, rel-4_12, rel-4_11, rel-4_1, rel-4_03
Changes since 1.6: +3 -3 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.5
5 root 1.3 use AnyEvent::Impl::Perl;
6 elmex 1.1 use AnyEvent::Handle;
7 root 1.6 use Test::More tests => 4;
8 elmex 1.1 use Socket;
9    
10 elmex 1.2 {
11     my $cv = AnyEvent->condvar;
12 elmex 1.1
13 elmex 1.2 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
14 elmex 1.1
15 root 1.4 my $rd_ae = AnyEvent::Handle->new (
16     fh => $rd,
17     on_eof => sub { $cv->broadcast },
18     );
19    
20 elmex 1.2 my $concat;
21 elmex 1.1
22 root 1.7 $rd_ae->push_read (line => sub {
23 root 1.4 is ($_[1], "A", 'A line was read correctly');
24     my $cb; $cb = sub {
25     $concat .= $_[1];
26 root 1.7 $_[0]->push_read (line => $cb);
27 root 1.4 };
28 root 1.7 $_[0]->push_read (line => $cb);
29 elmex 1.2 });
30    
31 root 1.4 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n";
32     close $wr;
33 elmex 1.2
34     $cv->wait;
35 root 1.4 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly');
36 elmex 1.2 }
37    
38     {
39     my $cv = AnyEvent->condvar;
40    
41     socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
42    
43     my $concat;
44    
45     my $rd_ae =
46     AnyEvent::Handle->new (
47 root 1.4 fh => $rd,
48     on_eof => sub { $cv->broadcast },
49     on_read => sub {
50 root 1.6 $_[0]->push_read (line => sub {
51 root 1.4 $concat .= "$_[1]:";
52     });
53 elmex 1.2 }
54     );
55    
56 root 1.4 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
57    
58 root 1.6 $wr_ae->push_write (netstring => "0:xx,,");
59 root 1.4 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
60     undef $wr;
61     undef $wr_ae;
62 elmex 1.1
63 root 1.6 $rd_ae->push_read (netstring => sub {
64     is ($_[1], "0:xx,,");
65     });
66    
67 elmex 1.2 $cv->wait;
68 elmex 1.1
69 root 1.4 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
70 elmex 1.2 }