about summary refs log tree commit diff
path: root/perl/lib/Nix/SSH.pm
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-24T10·24+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-24T10·24+0200
commit56131a2709d76a1e52bada83a083bd2cfee2f716 (patch)
tree7c0fc13a112606244d82e76bc489e34d98bbc2c0 /perl/lib/Nix/SSH.pm
parent01ddf53ee9ff77cbd7fc659740279a6ba80fbdae (diff)
Refactor
Diffstat (limited to 'perl/lib/Nix/SSH.pm')
-rw-r--r--perl/lib/Nix/SSH.pm21
1 files changed, 20 insertions, 1 deletions
diff --git a/perl/lib/Nix/SSH.pm b/perl/lib/Nix/SSH.pm
index 3bcbabe981d6..dd3e5cefd8c7 100644
--- a/perl/lib/Nix/SSH.pm
+++ b/perl/lib/Nix/SSH.pm
@@ -7,7 +7,8 @@ use IPC::Open2;
 our @ISA = qw(Exporter);
 our @EXPORT = qw(
   sshOpts openSSHConnection closeSSHConnection
-  readN readInt writeInt writeString writeStrings
+  readN readInt readString readStrings
+  writeInt writeString writeStrings
   connectToRemoteNix
 );
 
@@ -83,6 +84,24 @@ sub readInt {
 }
 
 
+sub readString {
+    my ($from) = @_;
+    my $len = readInt($from);
+    my $s = readN($len, $from);
+    readN(8 - $len % 8, $from) if $len % 8; # skip padding
+    return $s;
+}
+
+
+sub readStrings {
+    my ($from) = @_;
+    my $n = readInt($from);
+    my @res;
+    push @res, readString($from) while $n--;
+    return @res;
+}
+
+
 sub writeInt {
     my ($n, $to) = @_;
     syswrite($to, pack("L<x4", $n)) or die;