1#[cfg(feature = "compio")]
2mod io;
3
4#[cfg(feature = "compio")]
5pub(crate) mod compat {
6 use std::{io::Result, net, net::SocketAddr};
7
8 use ntex_io::Io;
9 use ntex_service::cfg::SharedCfg;
10
11 pub(crate) struct TcpStream(pub(crate) compio_net::TcpStream);
13
14 #[cfg(unix)]
15 pub(crate) struct UnixStream(pub(crate) compio_net::UnixStream);
17
18 pub async fn tcp_connect(addr: SocketAddr, cfg: SharedCfg) -> Result<Io> {
20 let sock = compio_net::TcpStream::connect(addr).await?;
21 Ok(Io::new(TcpStream(sock), cfg))
22 }
23
24 #[cfg(unix)]
25 pub async fn unix_connect<'a, P>(addr: P, cfg: SharedCfg) -> Result<Io>
27 where
28 P: AsRef<std::path::Path> + 'a,
29 {
30 let sock = compio_net::UnixStream::connect(addr).await?;
31 Ok(Io::new(UnixStream(sock), cfg))
32 }
33
34 pub fn from_tcp_stream(stream: net::TcpStream, cfg: SharedCfg) -> Result<Io> {
36 stream.set_nodelay(true)?;
37 Ok(Io::new(
38 TcpStream(compio_net::TcpStream::from_std(stream)?),
39 cfg,
40 ))
41 }
42
43 #[cfg(unix)]
44 pub fn from_unix_stream(
46 stream: std::os::unix::net::UnixStream,
47 cfg: SharedCfg,
48 ) -> Result<Io> {
49 Ok(Io::new(
50 UnixStream(compio_net::UnixStream::from_std(stream)?),
51 cfg,
52 ))
53 }
54}
55
56#[cfg(feature = "compio")]
57pub use self::compat::*;