shlist

share and manage lists between multiple people
Log | Files | Refs

commit e8e30e29e17fa14c6d1220e0366086d82f7cba1c
parent c0c7443e2ff040b2e10bee72db58e015a567ab4f
Author: kyle <kyle@0x30.net>
Date:   Wed,  9 Dec 2015 21:04:45 -0700

tests: upgrade tests.pm to sys{read,write} too

Diffstat:
Mtests/test.pm | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/tests/test.pm b/tests/test.pm @@ -52,15 +52,20 @@ sub new_socket sub send_msg { - my ($sock, $type_str, $contents) = @_; + my ($sock, $type_str, $msg) = @_; if (! exists $msg_num{$type_str}) { fail "$0: send_msg: invalid msg type '$type_str'"; } # send away - print $sock pack("nn", $msg_num{$type_str}, length($contents)); - print $sock $contents; + my ($n, $msg_len) = (0, length($msg)); + $n += $sock->syswrite(pack("nn", $msg_num{$type_str}, $msg_len)); + $n += $sock->syswrite($msg); + + if ($n != ($msg_len + 4)) { + fail "$0: send_msg: tried to send $msg_len bytes, but sent $n\n"; + } } sub recv_msg @@ -69,7 +74,7 @@ sub recv_msg # wait for response my ($metadata, $type, $size); - my $bread = read($sock, $metadata, 4); + my $bread = $sock->sysread($metadata, 4); unless (defined $bread) { fail "read(): $!\n"; } @@ -83,10 +88,12 @@ sub recv_msg if ($type >= @msg_str) { fail "$0: recv_msg: invalid msg num '$type'"; } - fail "bad message size not 0 <= $size < 1024" if ($size < 0 || $size > 1023); + + fail "bad message size not $size < 1024" if ($size > 1023); + return ($msg_str[$type], undef, 0) if ($size == 0); my $data; - if ((my $bread = read($sock, $data, $size)) != $size) { + if ((my $bread = $sock->sysread($data, $size)) != $size) { fail "read() returned $bread instead of $size!"; }