use std::io;
pub trait Duplex: Sized {
type Reader: io::Read + Send + 'static;
type Writer: crate::transport::WriteHalf;
fn split(self) -> io::Result<(Self::Reader, Self::Writer)>;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ConnectError {
ConnectTimeout,
PermissionDenied,
}
impl std::fmt::Display for ConnectError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::ConnectTimeout => "daemon connection timed out",
Self::PermissionDenied => "daemon endpoint permission denied",
})
}
}
impl std::error::Error for ConnectError {}
#[cfg(unix)]
pub mod unix;
#[cfg(unix)]
pub mod unix_socket;
#[cfg(windows)]
pub mod windows;
#[cfg(test)]
fn test_handshake(write: &mut impl io::Write, read: &mut impl io::Read, _: &str) -> io::Result<()> {
write.write_all(b"hello\n")?;
write.flush()?;
let mut reply = [0; 6];
read.read_exact(&mut reply)?;
if reply != *b"ready\n" {
return Err(io::Error::other("invalid test reply"));
}
Ok(())
}
#[cfg(all(windows, feature = "local-async"))]
pub mod windows_socket;