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, 10 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

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