Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
RT #116288, test that $socket.read will give us the whole cake
Even if .recv will get several chunks, read will concatenate all these.
  • Loading branch information
FROGGS committed Jan 10, 2013
1 parent 948ffc3 commit bbc7541
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
28 changes: 28 additions & 0 deletions S32-io/IO-Socket-INET.pl
Expand Up @@ -149,6 +149,34 @@
$sock.close();
}
}

when 6 { # test number 6 - read with parameter
if $server_or_client eq 'server' {
my $server = IO::Socket::INET.new(:localhost($host), :localport($port), :listen);
my $fd = open( $server_ready_flag_fn, :w );
$fd.close();
while my $client = $server.accept() {
# send 4 packets á 4096 bytes
for ^4 {
$client.send( $_ x 4096 );
sleep 1;
}
$client.close();
}
}
else {
until $server_ready_flag_fn.IO ~~ :e { sleep(0.1) }
unlink $server_ready_flag_fn;
my $sock = IO::Socket::INET.new(:$host, :$port);
# .read will give us 16kB of data even it recvs several chunks of smaller size
my $collected = $sock.read( 4096 * 4 );
say $collected.at_pos( 0 ).chr;
say $collected.at_pos( 4096 * 4 - 1 ).chr;
say $collected.bytes;
$sock.close();
}
}

}

=begin pod
Expand Down
14 changes: 13 additions & 1 deletion S32-io/IO-Socket-INET.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 16;
plan 19;

# L<S32::IO/IO::Socket::INET>

Expand Down Expand Up @@ -114,6 +114,18 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
is $expected[$i++], 'O frabjous day', '! separator not at end of string';
is $expected[$i++], ' Callooh', 'Multiple separators not at end of string';
is $expected[$i++], ' Callay', '! separator at end of string';

# test 6 tests read with a parameter
if $is-win {
$received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 6 $port};
} else {
$received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 6 $port};
}
$expected = $received.split("\n");
$i = 0;
is $expected[$i++], '0', 'received first character';
is $expected[$i++], '3', 'received last character';
is $expected[$i++], 4096 * 4, 'total amount ';
}
else {
skip "OS '$*OS' shell support not confirmed", 1;
Expand Down

0 comments on commit bbc7541

Please sign in to comment.