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