ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.3
Committed: Sun Apr 27 19:08:38 2008 UTC (16 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_3
Changes since 1.2: +4 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!perl
2
3 use strict;
4 use AnyEvent::Impl::Perl;
5 use AnyEvent::Handle;
6 use Test::More tests => 2;
7 use Socket;
8
9 {
10 my $cv = AnyEvent->condvar;
11
12 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
13
14 my $rd_ae = AnyEvent::Handle->new (fh => $rd);
15 my $concat;
16
17 $rd_ae->on_eof (sub { $cv->broadcast });
18 $rd_ae->readlines (sub {
19 my ($rd_ae, @lines) = @_;
20 for (@lines) {
21 chomp;
22 $concat .= $_;
23 }
24 });
25
26 $wr->syswrite ("A\nBC\nDEF\nG\n");
27 $wr->syswrite (("X" x 113) . "\n");
28 $wr->close;
29
30 $cv->wait;
31
32 is ($concat, "ABCDEFG".("X" x 113), 'lines were read correctly');
33 }
34
35 {
36 my $cv = AnyEvent->condvar;
37
38 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
39
40 my $concat;
41
42 my $rd_ae =
43 AnyEvent::Handle->new (
44 fh => $rd,
45 on_eof => sub { $cv->broadcast },
46 on_readline => sub {
47 my ($rd_ae, @lines) = @_;
48 for (@lines) {
49 chomp;
50 $concat .= $_;
51 }
52 }
53 );
54
55 $wr->syswrite ("A\nBC\nDEF\nG\n");
56 $wr->syswrite (("X" x 113) . "\n");
57 $wr->close;
58
59 $cv->wait;
60
61 is ($concat, "ABCDEFG".("X" x 113), 'second lines were read correctly');
62 }