ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.12
Committed: Thu Aug 21 23:48:35 2008 UTC (15 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_91, rel-4_412, rel-4_81, rel-4_83, rel-4_82, rel-4_86, rel-4_352, rel-5_112, rel-4_351, rel-5_251, rel-0_85, rel-4_331, rel-4_233, rel-4_8, rel-4_234, rel-4_4, rel-5_261, rel-5_271, rel-5_28, rel-5_29, rel-5_21, rel-5_22, rel-5_23, rel-5_24, rel-5_26, rel-5_27, rel-5_1, rel-5_0, rel-5_2, rel-5_201, rel-5_202, rel-5_111, rel-4_881, rel-4_411, rel-4_9, rel-5_01, rel-4_45, rel-4_41, rel-4_42, rel-4_88, rel-4_3, rel-5_11, rel-5_12, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35
Changes since 1.11: +4 -1 lines
Log Message:
4.233

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