1 |
elmex |
1.1 |
#!perl |
2 |
root |
1.3 |
|
3 |
elmex |
1.1 |
use strict; |
4 |
root |
1.5 |
|
5 |
root |
1.3 |
use AnyEvent::Impl::Perl; |
6 |
elmex |
1.1 |
use AnyEvent::Handle; |
7 |
root |
1.4 |
use Test::More tests => 3; |
8 |
elmex |
1.1 |
use Socket; |
9 |
|
|
|
10 |
elmex |
1.2 |
{ |
11 |
|
|
my $cv = AnyEvent->condvar; |
12 |
elmex |
1.1 |
|
13 |
elmex |
1.2 |
socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
14 |
elmex |
1.1 |
|
15 |
root |
1.4 |
my $rd_ae = AnyEvent::Handle->new ( |
16 |
|
|
fh => $rd, |
17 |
|
|
on_eof => sub { $cv->broadcast }, |
18 |
|
|
); |
19 |
|
|
|
20 |
elmex |
1.2 |
my $concat; |
21 |
elmex |
1.1 |
|
22 |
root |
1.4 |
$rd_ae->push_read_line (sub { |
23 |
|
|
is ($_[1], "A", 'A line was read correctly'); |
24 |
|
|
my $cb; $cb = sub { |
25 |
|
|
$concat .= $_[1]; |
26 |
|
|
$_[0]->push_read_line ($cb); |
27 |
|
|
}; |
28 |
|
|
$_[0]->push_read_line ($cb); |
29 |
elmex |
1.2 |
}); |
30 |
|
|
|
31 |
root |
1.4 |
syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; |
32 |
|
|
close $wr; |
33 |
elmex |
1.2 |
|
34 |
|
|
$cv->wait; |
35 |
root |
1.4 |
is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly'); |
36 |
elmex |
1.2 |
} |
37 |
|
|
|
38 |
|
|
{ |
39 |
|
|
my $cv = AnyEvent->condvar; |
40 |
|
|
|
41 |
|
|
socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
42 |
|
|
|
43 |
|
|
my $concat; |
44 |
|
|
|
45 |
|
|
my $rd_ae = |
46 |
|
|
AnyEvent::Handle->new ( |
47 |
root |
1.4 |
fh => $rd, |
48 |
|
|
on_eof => sub { $cv->broadcast }, |
49 |
|
|
on_read => sub { |
50 |
|
|
$_[0]->push_read_line (sub { |
51 |
|
|
$concat .= "$_[1]:"; |
52 |
|
|
}); |
53 |
elmex |
1.2 |
} |
54 |
|
|
); |
55 |
|
|
|
56 |
root |
1.4 |
my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; |
57 |
|
|
|
58 |
|
|
$wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); |
59 |
|
|
undef $wr; |
60 |
|
|
undef $wr_ae; |
61 |
elmex |
1.1 |
|
62 |
elmex |
1.2 |
$cv->wait; |
63 |
elmex |
1.1 |
|
64 |
root |
1.4 |
is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); |
65 |
elmex |
1.2 |
} |