summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbold <bold@cryptoguru.com>2020-01-27 06:27:42 +0100
committerWez Furlong <wez@wezfurlong.org>2020-01-26 23:08:05 -0800
commite43929d52795a047942a5c14281707bf8c69d5c4 (patch)
tree8798c561dcb97c1553ad4e6e08aac0311dea60ec
parent90a12ff33fef3fd12132672e56a6ad572b342ef0 (diff)
downloadssh2-rs-e43929d52795a047942a5c14281707bf8c69d5c4.zip
replace tcp stream accessor with std traits to obtain raw fds
-rw-r--r--src/session.rs38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/session.rs b/src/session.rs
index 6364020..21a137b 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -298,22 +298,6 @@ impl Session {
let _ = inner.tcp.replace(Box::new(stream));
}
- /// Returns the raw fd of the stream that was associated with the Session by
- /// the Session::handshake method.
- #[cfg(unix)]
- pub fn tcp_stream(&self) -> Option<RawFd> {
- let inner = self.inner();
- inner.tcp.as_ref().map(|tcp| tcp.as_raw_fd())
- }
-
- /// Returns the raw socket of the stream that was associated with the
- /// Session by the Session::handshake method.
- #[cfg(windows)]
- pub fn tcp_stream(&self) -> Option<RawSocket> {
- let inner = self.inner();
- inner.tcp.as_ref().map(|tcp| tcp.as_raw_socket())
- }
-
/// Attempt basic password authentication.
///
/// Note that many SSH servers which appear to support ordinary password
@@ -1020,6 +1004,28 @@ impl Session {
}
}
+#[cfg(unix)]
+impl AsRawFd for Session {
+ fn as_raw_fd(&self) -> RawFd {
+ let inner = self.inner();
+ match inner.tcp.as_ref() {
+ Some(tcp) => tcp.as_raw_fd(),
+ None => panic!("tried to obtain raw fd without tcp stream set"),
+ }
+ }
+}
+
+#[cfg(windows)]
+impl AsRawSocket for Session {
+ fn as_raw_socket(&self) -> RawSocket {
+ let inner = self.inner();
+ match inner.tcp.as_ref() {
+ Some(tcp) => tcp.as_raw_socket(),
+ None => panic!("tried to obtain raw socket without tcp stream set"),
+ }
+ }
+}
+
impl SessionInner {
/// Translate a return code into a Rust-`Result`.
pub fn rc(&self, rc: c_int) -> Result<(), Error> {