tokuhirom
10/1/2015 - 7:11 AM

perl6 react server stuck

perl6 react server stuck

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 });
    }
}
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";