ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.14
Committed: Fri Aug 26 03:34:01 2011 UTC (12 years, 11 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-7_05, rel-7_07, rel-7_01, rel-7_02, rel-7_03, rel-7_08, rel-7_09, rel-7_16, rel-7_13, rel-7_11, rel-6_1, rel-6_11, rel-6_12, rel-6_13, rel-7_15, rel-7_14, rel-7_12, rel-6_02, rel-6_01, rel-7_0, rel-7_04, rel-6_14, HEAD
Changes since 1.13: +3 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 #!perl
2 root 1.3
3 root 1.11 # actually tests a few other read/write types as well
4    
5 elmex 1.1 use strict;
6 root 1.5
7 root 1.13 use AnyEvent;
8     BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }
9 elmex 1.1 use AnyEvent::Handle;
10 root 1.14 use AnyEvent::Util;
11 root 1.10 use Test::More tests => 8;
12 elmex 1.1 use Socket;
13 root 1.11 use Errno;
14 elmex 1.1
15 elmex 1.2 {
16     my $cv = AnyEvent->condvar;
17 elmex 1.1
18 root 1.14 my ($rd, $wr) = portable_socketpair;
19 elmex 1.1
20 root 1.4 my $rd_ae = AnyEvent::Handle->new (
21 root 1.8 fh => $rd,
22     on_error => sub {
23 root 1.11 ok ($! == &Errno::EPIPE);
24 root 1.12 $cv->broadcast;
25     },
26     on_eof => sub {
27     ok (0, "got eof");
28 root 1.8 },
29 root 1.4 );
30    
31 elmex 1.2 my $concat;
32 elmex 1.1
33 root 1.7 $rd_ae->push_read (line => sub {
34 root 1.4 is ($_[1], "A", 'A line was read correctly');
35     my $cb; $cb = sub {
36     $concat .= $_[1];
37 root 1.7 $_[0]->push_read (line => $cb);
38 root 1.4 };
39 root 1.7 $_[0]->push_read (line => $cb);
40 elmex 1.2 });
41    
42 root 1.8 syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012";
43 root 1.4 close $wr;
44 elmex 1.2
45     $cv->wait;
46 root 1.8 is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly');
47 elmex 1.2 }
48    
49     {
50     my $cv = AnyEvent->condvar;
51    
52 root 1.14 my ($rd, $wr) = portable_socketpair;
53 elmex 1.2
54     my $concat;
55    
56     my $rd_ae =
57     AnyEvent::Handle->new (
58 root 1.4 fh => $rd,
59     on_eof => sub { $cv->broadcast },
60     on_read => sub {
61 root 1.6 $_[0]->push_read (line => sub {
62 root 1.4 $concat .= "$_[1]:";
63     });
64 elmex 1.2 }
65     );
66    
67 root 1.4 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
68    
69 root 1.8 undef $wr;
70     undef $rd;
71    
72 root 1.6 $wr_ae->push_write (netstring => "0:xx,,");
73 root 1.8 $wr_ae->push_write (netstring => "");
74 root 1.10 $wr_ae->push_write (storable => [4,3,2]);
75 root 1.9 $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here
76 root 1.10 $wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012");
77 root 1.4 undef $wr_ae;
78 elmex 1.1
79 root 1.10 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,") });
80     $rd_ae->push_read (netstring => sub { is ($_[1], "") });
81     $rd_ae->push_read (storable => "w", sub { is ("@{$_[1]}", "4 3 2") });
82     $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999) });
83 root 1.6
84 elmex 1.2 $cv->wait;
85 elmex 1.1
86 root 1.10 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly');
87 elmex 1.2 }
88 root 1.8