1 |
elmex |
1.1 |
#!perl |
2 |
root |
1.3 |
|
3 |
elmex |
1.1 |
use strict; |
4 |
root |
1.3 |
use AnyEvent::Impl::Perl; |
5 |
elmex |
1.1 |
use AnyEvent::Handle; |
6 |
elmex |
1.2 |
use Test::More tests => 2; |
7 |
elmex |
1.1 |
use Socket; |
8 |
|
|
|
9 |
elmex |
1.2 |
{ |
10 |
|
|
my $cv = AnyEvent->condvar; |
11 |
elmex |
1.1 |
|
12 |
elmex |
1.2 |
socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
13 |
elmex |
1.1 |
|
14 |
elmex |
1.2 |
my $rd_ae = AnyEvent::Handle->new (fh => $rd); |
15 |
|
|
my $concat; |
16 |
elmex |
1.1 |
|
17 |
elmex |
1.2 |
$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 |
root |
1.3 |
is ($concat, "ABCDEFG".("X" x 113), 'lines were read correctly'); |
33 |
elmex |
1.2 |
} |
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 |
elmex |
1.1 |
|
59 |
elmex |
1.2 |
$cv->wait; |
60 |
elmex |
1.1 |
|
61 |
root |
1.3 |
is ($concat, "ABCDEFG".("X" x 113), 'second lines were read correctly'); |
62 |
elmex |
1.2 |
} |