mod os;
pub use core::net::SocketAddr;
pub use os::OsSocket as OsBlockingSocket;
use crate::error::SocketError;
pub trait BlockingSocket {
fn connect(
&mut self,
addr: &SocketAddr,
host: &str,
) -> Result<(), SocketError>;
fn read(
&mut self,
buf: &mut [u8],
) -> Result<usize, SocketError>;
fn write(
&mut self,
buf: &[u8],
) -> Result<usize, SocketError>;
fn write_vectored(
&mut self,
bufs: &[&[u8]],
) -> Result<usize, SocketError> {
for buf in bufs {
if !buf.is_empty() {
return self.write(buf);
}
}
Ok(0)
}
fn shutdown(&mut self) -> Result<(), SocketError>;
fn set_read_timeout(
&mut self,
timeout_ms: u32,
) -> Result<(), SocketError>;
fn set_write_timeout(
&mut self,
timeout_ms: u32,
) -> Result<(), SocketError>;
fn set_connect_timeout(
&mut self,
timeout_ms: u32,
) -> Result<(), SocketError> {
let _ = timeout_ms;
Ok(())
}
#[must_use]
fn is_os_cleartext() -> bool
where
Self: Sized,
{
true
}
}
pub trait BlockingSocketFactory: BlockingSocket + Sized {
fn new() -> Result<Self, SocketError>;
}