-
Notifications
You must be signed in to change notification settings - Fork 135
/
socket-accept-and-working-threads.t
72 lines (61 loc) · 1.79 KB
/
socket-accept-and-working-threads.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
66
67
68
69
70
71
72
use Test;
plan 15;
# https://github.com/Raku/old-issue-tracker/issues/5643
{
my class Dummy { has ($.a, $.b, $.c, $.d, $.e) }
my $c = Channel.new;
my $ready = Promise.new;
start {
my $listen = IO::Socket::INET.new(:listen, :localport(10333));
$ready.keep(True);
loop {
my $conn = $listen.accept;
while my $buf = $conn.recv(:bin) {
$conn.write: $buf;
start {
Dummy.new(:1a, :2b, :3c, :4d, :5e) for ^3000;
$c.send('ok');
}
}
$conn.close;
}
}
await $ready;
for ^5 {
my $conn = IO::Socket::INET.new(:host<127.0.0.1>, :port(10333));
$conn.print: "Don't hang up";
is $conn.recv, "Don't hang up", "Server responded ($_)";
$conn.close;
}
for ^5 {
is $c.receive, 'ok', "Started work was completed ($_)";
}
}
# https://github.com/MoarVM/MoarVM/issues/1650
# could not recv in a thread besides where the socket was accepted
{
my $ready = Promise.new;
start {
my $listen = IO::Socket::INET.new(:listen, :localport(10334));
$ready.keep(True);
loop {
my $conn = $listen.accept;
start {
CATCH { default { diag $_ } }
while my $buf = $conn.recv(:bin) {
$conn.write: $buf;
}
$conn.close;
}
}
}
await $ready;
for ^5 {
my $conn = IO::Socket::INET.new(:host<127.0.0.1>, :port(10334));
$conn.print: "Can be handled on a thread";
is $conn.recv, "Can be handled on a thread",
"Server with recv on different thread responded ($_)";
$conn.close;
}
}
# vim: expandtab shiftwidth=4