New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sockets not thread safe on windows #12756
Comments
From goossen@textkernel.nlCreated by goossen@textkernel.nlcreating and freeing sockets appears not to be thread safe on windows. Perl Info
|
From goossen@textkernel.nl#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use threads;
use threads::shared;
use File::Spec;
use IO::Select;
use IO::Socket::INET;
plan "no_plan";
our $G_LOCK = &share( [] );
my $use_lock = 0;
my $input = "foobar\n";
my $output = "baz\n";
my $port = 11100;
threads->create( sub {
print "server\n";
my $listen = IO::Socket::INET->new( Listen => 15, Proto => "tcp", LocalAddr => "localhost", LocalPort => $port ) or die $!;
print "waiting\n";
while (1) {
my $sel = IO::Select->new($listen);
$sel->can_read() or die "Failed can_read: $!";
my $sock;
{
lock $G_LOCK if $use_lock;
$sock = $listen->accept();
}
eval {
my $line = $sock->getline();
$sock->print($output);
# sleep 0.1;
lock $G_LOCK if $use_lock;
$sock->close;
};
warn "SERVER: $@" if $@;
}
die "FAILED accept: $!";
exit;
}
);
sleep 3;
my $G_NO_OF_THREADS = 10;
for my $ground ( 1 .. 3 ) {
print STDERR "\n\nGLOBAL ROUND $ground\n\n";
my @threads;
for ( 1 .. $G_NO_OF_THREADS ) {
push @threads, threads->create( \&test_process_many );
}
for (@threads) {
is( $_->join, '', "no error in thread" );
}
}
sub test_process_many {
eval {
for my $i ( 1 .. 1000 ) {
test_process($input, $output);
}
};
warn "CLIENT: $@" if $@;
return $@;
}
sub test_process {
my ( $input, $exp_res ) = @_;
my $socket;
{
lock $G_LOCK if $use_lock;
$socket = IO::Socket::INET->new( PeerAddr => "localhost:$port" );
die "failed creating socket: $!" unless $socket;
}
$socket->print($input);
my @res = <$socket>;
my $res = join "", @res;
$res =~ s/\r\n/\n/g;
$res eq $exp_res or die "Invalid result '$res'";
{
lock $G_LOCK if $use_lock;
$socket->close();
}
return;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Migrated from rt.perl.org#116641 (status was 'new')
Searchable as RT116641$
The text was updated successfully, but these errors were encountered: