#[cfg(not(target_os = "windows"))] pub use smol::net::unix::{UnixListener, UnixStream}; #[cfg(target_os = "windows")] pub use windows::{UnixListener, UnixStream}; #[cfg(target_os = "windows")] pub mod windows { use std::{ io::Result, path::Path, pin::Pin, task::{Context, Poll}, }; use smol::{ Async, io::{AsyncRead, AsyncWrite}, }; pub struct UnixListener(Async); impl UnixListener { pub fn bind>(path: P) -> Result { Ok(UnixListener(Async::new(crate::UnixListener::bind(path)?)?)) } pub async fn accept(&self) -> Result<(UnixStream, ())> { let (sock, _) = self.0.read_with(|listener| listener.accept()).await?; Ok((UnixStream(Async::new(sock)?), ())) } } pub struct UnixStream(Async); impl UnixStream { pub async fn connect>(path: P) -> Result { Ok(UnixStream(Async::new(crate::UnixStream::connect(path)?)?)) } } impl AsyncRead for UnixStream { fn poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { Pin::new(&mut self.0).poll_read(cx, buf) } } impl AsyncWrite for UnixStream { fn poll_write( mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { Pin::new(&mut self.0).poll_write(cx, buf) } fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Pin::new(&mut self.0).poll_flush(cx) } fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Pin::new(&mut self.0).poll_close(cx) } } }