1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::{
io::{Error as IoError, ErrorKind as IoErrorKind},
net::SocketAddr,
};
use ssh2::Error as Ssh2Error;
pub fn ssh2_error_is_would_block(err: &Ssh2Error) -> bool {
IoError::from(Ssh2Error::from_errno(err.code())).kind() == IoErrorKind::WouldBlock
}
#[derive(Debug, Clone)]
pub enum ConnectInfo {
Tcp(SocketAddr),
#[cfg(unix)]
Unix(Box<std::path::Path>),
}
impl ConnectInfo {
pub fn with_tcp(addr: impl Into<SocketAddr>) -> Self {
Self::Tcp(addr.into())
}
#[cfg(unix)]
pub fn with_unix(path: impl AsRef<std::path::Path>) -> Self {
Self::Unix(path.as_ref().into())
}
}
#[cfg(windows)]
pub struct RawSocketWrapper(pub std::os::windows::io::RawSocket);
#[cfg(windows)]
impl std::os::windows::io::AsRawSocket for RawSocketWrapper {
#[inline]
fn as_raw_socket(&self) -> std::os::windows::io::RawSocket {
self.0
}
}