/
socket-host-port-split.t
65 lines (52 loc) 路 1.34 KB
/
socket-host-port-split.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use v6;
use Test;
# RT #130474
plan 2;
{
my $localhost = '0.0.0.0:5014';
my $host = '127.0.0.1:5014';
my $family = PF_INET;
split-host-port :$localhost, :$host, :$family;
}
#?rakudo skip 'Hangs on boxes without IPv6 support'
#?DOES 1
{
my $localhost = '[::]:5014';
my $host = '[::1]:5014';
my $family = PF_INET6;
split-host-port :$localhost, :$host, :$family;
}
sub split-host-port(:$localhost, :$host, :$family) {
my $c = Channel.new;
my $ready = Promise.new;
start {
my $listen = IO::Socket::INET.new(
:$localhost,
:listen,
:$family,
);
$ready.keep(True);
loop {
my $connection = $listen.accept;
while my $buffer = $connection.recv(:bin) {
$connection.write: $buffer;
start {
$c.send('ok');
}
}
$connection.close;
}
}
await $ready;
my $connection = IO::Socket::INET.new(
:$host,
:$family,
);
$connection.print: "Don't hang up";
is $connection.recv, "Don't hang up",
"{ $family == PF_INET ?? 'IPv4'
!! $family == PF_INET6 ?? 'IPv6'
!! die 'Invalid INET family value'} server responded";
$connection.close;
}
# vim: ft=perl6