diff options
author | Peter Palfrader <peter@palfrader.org> | 2004-04-24 16:21:48 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2004-04-24 16:21:48 +0000 |
commit | e7479537b614de3690ff767f6d407b56b74d7160 (patch) | |
tree | 24bfd54fd5ca4cc8573a7a744d4a62f66fc9c42c /Echolot/Tools.pm | |
parent | b262791a005380732f079d51f6cff9970df70ee2 (diff) |
Steal cabot's readwritegpg
Diffstat (limited to 'Echolot/Tools.pm')
-rw-r--r-- | Echolot/Tools.pm | 36 |
1 files changed, 24 insertions, 12 deletions
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) = @_; |