From 16cb2862ff01ba4a703cda59dfadbad443aa5738 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 1 Aug 2019 21:32:35 -0700 Subject: handle_extended_data Add a function to configure how extended data streams are to be handled. This allows for merging stderr to stdout, or discarding it. --- src/channel.rs | 10 +++++++++- src/lib.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/channel.rs b/src/channel.rs index 7086f5d..69b535a 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -5,7 +5,7 @@ use std::io::prelude::*; use std::rc::Rc; use std::slice; -use {raw, Error, SessionInner}; +use {raw, Error, ExtendedData, SessionInner}; /// A channel represents a portion of an SSH connection on which data can be /// read and written. @@ -224,6 +224,14 @@ impl Channel { } } + /// Change how extended data (such as stderr) is handled + pub fn handle_extended_data(&mut self, mode: ExtendedData) -> Result<(), Error> { + unsafe { + let rc = raw::libssh2_channel_handle_extended_data2(self.raw, mode as c_int); + self.sess.rc(rc) + } + } + /// Returns the exit code raised by the process running on the remote host /// at the other end of the named channel. /// diff --git a/src/lib.rs b/src/lib.rs index db3591a..dd02a67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -289,3 +289,15 @@ impl From for KnownHostKeyFormat { } } } + +/// How to handle extended data streams, such as stderr +#[derive(Copy, Clone, Debug)] +pub enum ExtendedData { + /// Queue extended data for eventual reading + Normal = raw::LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL as isize, + /// Treat extended data and ordinary data the same. Merge all substreams such that calls to + /// read will pull from all substreams on a first-in/first-out basis. + Merge = raw::LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE as isize, + /// Discard all extended data as it arrives. + Ignore = raw::LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE as isize, +} -- cgit v1.2.3