From e7479537b614de3690ff767f6d407b56b74d7160 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 24 Apr 2004 16:21:48 +0000 Subject: Steal cabot's readwritegpg --- Echolot/Tools.pm | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'Echolot') diff --git a/Echolot/Tools.pm b/Echolot/Tools.pm index bc88219..b8a2a4b 100644 --- a/Echolot/Tools.pm +++ b/Echolot/Tools.pm @@ -278,27 +278,39 @@ sub make_gpg_fds() { sub readwrite_gpg($$$$$) { my ($in, $inputfd, $stdoutfd, $stderrfd, $statusfd) = @_; local $INPUT_RECORD_SEPARATOR = undef; - my $s = IO::Select->new(); + my $sout = IO::Select->new(); + my $sin = IO::Select->new(); + my $offset = 0; + $inputfd->blocking(0); $stdoutfd->blocking(0); $statusfd->blocking(0); $stderrfd->blocking(0); - $s->add($stdoutfd); - $s->add($stderrfd); - $s->add($statusfd); + $sout->add($stdoutfd); + $sout->add($stderrfd); + $sout->add($statusfd); + $sin->add($inputfd); my ($stdout, $stderr, $status) = ("", "", ""); - print $inputfd $in; close $inputfd; + my ($readyr, $readyw, $written); + while ($sout->count() > 0) { + ($readyr, $readyw, undef) = IO::Select::select($sout, $sin, undef, 42); + foreach my $wfd (@$readyw) { + $written = $wfd->syswrite($in, length($in) - $offset, $offset); + $offset += $written; + if ($offset == length($in)) { + close $wfd; + $sin->remove($wfd); + $sin = undef; + } + } - my @ready; - while ($s->count() > 0) { - @ready = $s->can_read(42); - next unless (scalar(@ready)); # Wait some more. + next unless (defined(@$readyr)); # Wait some more. - for my $rfd (@ready) { + for my $rfd (@$readyw) { if ($rfd->eof) { - $s->remove($rfd); + $sout->remove($rfd); close($rfd); next; } @@ -317,7 +329,7 @@ sub readwrite_gpg($$$$$) { } } return ($stdout, $stderr, $status); -} +}; sub crypt_symmetrically($$) { my ($msg, $direction) = @_; -- cgit v1.2.3