From 2608ac124734be3c79c40dfe3ed3ba8e058940ec Mon Sep 17 00:00:00 2001 From: Alexandr Ciornii Date: Sun, 1 May 2016 10:20:07 +0300 Subject: [PATCH] fix hanging on Windows (RT#71319) --- t/100_flush_bug-win32.pl | 30 +++++++++++++++++++++++ t/100_flush_bug.t | 51 ++++++++++++++++++++++++++-------------- 2 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 t/100_flush_bug-win32.pl diff --git a/t/100_flush_bug-win32.pl b/t/100_flush_bug-win32.pl new file mode 100644 index 0000000..fd67638 --- /dev/null +++ b/t/100_flush_bug-win32.pl @@ -0,0 +1,30 @@ + +use strict; +use IO::Socket::INET; + +my @res = ( + ["OK\r\n", 1], + ["ERROR\r\n", 0], + ["\r\nERROR\r\n", 0], + ["FOO\r\nERROR\r\n", 0], + ["FOO\r\nOK\r\nERROR\r\n", 0], + ["\r\n\r\nOK\r\n", 0], + ["END\r\n", 0], +); + + +my $testaddr = shift || die; + my $sock = IO::Socket::INET->new( + LocalAddr => $testaddr, + Proto => 'tcp', + ReuseAddr => 1, + Listen => 1, + ) or die "cannot open $testaddr: $!"; + my $csock = $sock->accept(); + while (defined (my $buf = <$csock>)) { + my $res = shift @res; + print $csock $res->[0]; + } + close $csock; + close $sock; + exit 0; diff --git a/t/100_flush_bug.t b/t/100_flush_bug.t index f6621a9..0bada6e 100644 --- a/t/100_flush_bug.t +++ b/t/100_flush_bug.t @@ -13,6 +13,7 @@ my $sock = IO::Socket::INET->new( ReuseAddr => 1, ); +#should be in 100_flush_bug-win32.pl too my @res = ( ["OK\r\n", 1], ["ERROR\r\n", 0], @@ -31,24 +32,36 @@ if ($sock) { } close $sock; -my $pid = fork; -die "Cannot fork because: '$!'" unless defined $pid; -unless ($pid) { - - my $sock = IO::Socket::INET->new( - LocalAddr => $testaddr, - Proto => 'tcp', - ReuseAddr => 1, - Listen => 1, - ) or die "cannot open $testaddr: $!"; - my $csock = $sock->accept(); - while (defined (my $buf = <$csock>)) { - my $res = shift @res; - print $csock $res->[0]; +my $processobj; +if ($^O eq 'MSWin32') { + require Win32::Process; + Win32::Process::Create($processobj, + "$^X", + "$^X t/100_flush_bug-win32.pl $testaddr", + 0, + 32 + 134217728, #NORMAL_PRIORITY_CLASS + CREATE_NO_WINDOW + ".") || die $^E; + +} else { + my $pid = fork; + die "Cannot fork because: '$!'" unless defined $pid; + unless ($pid) { + + my $sock = IO::Socket::INET->new( + LocalAddr => $testaddr, + Proto => 'tcp', + ReuseAddr => 1, + Listen => 1, + ) or die "cannot open $testaddr: $!"; + my $csock = $sock->accept(); + while (defined (my $buf = <$csock>)) { + my $res = shift @res; + print $csock $res->[0]; + } + close $csock; + close $sock; + exit 0; } - close $csock; - close $sock; - exit 0; } # give the forked server a chance to startup @@ -60,3 +73,7 @@ for (@res) { ($_->[0] =~ s/\W//g); is $memd->flush_all, $_->[1], $_->[0]; } + +if ($processobj) { + $processobj->Wait(1000) or $processobj->Kill(0); +}