From 42d91b079c5d0b468663511e7b2a8e2f4048c475 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 10 Jul 2014 21:14:34 +0200 Subject: Fix use of sysread --- perl/lib/Nix/CopyClosure.pm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/perl/lib/Nix/CopyClosure.pm b/perl/lib/Nix/CopyClosure.pm index 779d7439f677..8be4ead763d2 100644 --- a/perl/lib/Nix/CopyClosure.pm +++ b/perl/lib/Nix/CopyClosure.pm @@ -7,11 +7,24 @@ use List::Util qw(sum); use IPC::Open2; +sub readN { + my ($bytes, $from) = @_; + my $res = ""; + while ($bytes > 0) { + my $s; + my $n = sysread($from, $s, $bytes); + die "I/O error reading from remote side\n" if !defined $n; + die "got EOF while expecting $bytes bytes from remote side\n" if !$n; + $bytes -= $n; + $res .= $s; + } + return $res; +} + + sub readInt { my ($from) = @_; - my $resp; - sysread($from, $resp, 8) == 8 or die "did not receive valid reply from remote host\n"; - return unpack("L