pub mod endpoint;
#[cfg(feature = "inproc")]
pub mod inproc;
#[cfg(feature = "inproc")]
pub mod inproc_stream;
#[cfg(feature = "ipc")]
pub mod ipc;
pub mod tcp;
use std::os::fd::AsRawFd;
use tokio::io::{AsyncRead, AsyncWrite};
pub(crate) trait ZmtpReadHalf: AsyncRead + Unpin + Send + std::fmt::Debug + 'static {
#[cfg(feature = "io-uring")]
fn try_recv_bytes(&mut self) -> Option<std::io::Result<bytes::Bytes>> {
None
}
#[cfg(feature = "io-uring")]
fn steal_current_bytes(&mut self) -> Option<bytes::Bytes> {
None
}
#[cfg(feature = "io-uring")]
fn poll_recv_bytes(
self: std::pin::Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<std::io::Result<bytes::Bytes>> {
std::task::Poll::Ready(Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"poll_recv_bytes not supported for this stream type",
)))
}
fn try_read_chunk(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
Err(std::io::Error::from(std::io::ErrorKind::WouldBlock))
}
}
pub(crate) trait ZmtpWriteHalf: AsyncWrite + Unpin + Send + std::fmt::Debug + 'static {
fn supports_owned_write(&self) -> bool {
false
}
fn write_owned(
&mut self,
_bufs: Vec<bytes::Bytes>,
) -> impl std::future::Future<Output = std::io::Result<()>> + Send {
async {
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"write_owned not supported for this transport",
))
}
}
fn set_cork(&self, _enable: bool) {}
}
pub(crate) trait ZmtpStdStream:
AsyncRead + AsyncWrite + AsRawFd + Unpin + Send + std::fmt::Debug + 'static
{
type ReadHalf: ZmtpReadHalf;
type WriteHalf: ZmtpWriteHalf;
fn into_split(self) -> (Self::ReadHalf, Self::WriteHalf);
}
impl ZmtpReadHalf for tokio::net::tcp::OwnedReadHalf {
fn try_read_chunk(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
tokio::net::tcp::OwnedReadHalf::try_read(self, buf)
}
}
impl ZmtpWriteHalf for tokio::net::tcp::OwnedWriteHalf {}
impl ZmtpStdStream for tokio::net::TcpStream {
type ReadHalf = tokio::net::tcp::OwnedReadHalf;
type WriteHalf = tokio::net::tcp::OwnedWriteHalf;
fn into_split(self) -> (Self::ReadHalf, Self::WriteHalf) {
tokio::net::TcpStream::into_split(self)
}
}
#[cfg(feature = "ipc")]
impl ZmtpReadHalf for tokio::net::unix::OwnedReadHalf {
fn try_read_chunk(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
tokio::net::unix::OwnedReadHalf::try_read(self, buf)
}
}
#[cfg(feature = "ipc")]
impl ZmtpWriteHalf for tokio::net::unix::OwnedWriteHalf {}
#[cfg(feature = "ipc")]
impl ZmtpStdStream for tokio::net::UnixStream {
type ReadHalf = tokio::net::unix::OwnedReadHalf;
type WriteHalf = tokio::net::unix::OwnedWriteHalf;
fn into_split(self) -> (Self::ReadHalf, Self::WriteHalf) {
tokio::net::UnixStream::into_split(self)
}
}