Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Last active October 1, 2015 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokuhirom/0b6901f3cea1c3bf6170 to your computer and use it in GitHub Desktop.
Save tokuhirom/0b6901f3cea1c3bf6170 to your computer and use it in GitHub Desktop.
perl6 react server stuck
use strict;
use warnings;
use utf8;
use 5.010000;
use IO::Socket::INET;
my $port = 3000;
my $n = 1000;
my $success = 0;
my $fail = 0;
for (1..$n) {
my $sock = IO::Socket::INET->new(
PeerHost => 'localhost',
PeerPort => $port,
Proto => 'tcp',
) or do {
print "cannot connect: $!\n";
$fail++;
};
my $got = <$sock>;
if (($got//'') eq "hello\n") {
$success++;
} else {
$fail++;
}
}
print "success:$success fail: $fail\n";
use v6;
my $msg = "hello\n".encode('utf-8');
react {
whenever IO::Socket::Async.listen('127.0.0.1', 3000) -> $conn {
$conn.write($msg).then({ $conn.close });
}
}
@tokuhirom
Copy link
Author

In my environment, client.pl outputs

success:941 fail: 59

my environment is:

$ perl6 --version
This is perl6 version 2015.09-191-g649dae1 built on MoarVM version 2015.09-39-g1434283
$ uname -a
Linux www3301gi.sakura.ne.jp 3.10.0-229.1.2.el7.x86_64 #1 SMP Fri Mar 27 03:04:26 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment