package Nix::SSH; use utf8; use strict; use File::Temp qw(tempdir); use IPC::Open2; our @ISA = qw(Exporter); our @EXPORT = qw( @globalSshOpts readN readInt readString readStrings writeInt writeString writeStrings connectToRemoteNix ); our @globalSshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or ""); 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) = @_; return unpack("L= 0x300; return ($from, $to, $pid); } 1;