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