ntex_net/
compat.rs

1//! Utility for async runtime abstraction
2
3#[cfg(feature = "tokio")]
4pub use ntex_tokio::{from_tcp_stream, tcp_connect};
5
6#[cfg(all(unix, feature = "tokio"))]
7pub use ntex_tokio::{from_unix_stream, unix_connect};
8
9#[cfg(all(feature = "compio", not(feature = "tokio"), not(feature = "neon")))]
10pub use ntex_compio::{from_tcp_stream, tcp_connect};
11
12#[cfg(all(
13    unix,
14    feature = "compio",
15    not(feature = "tokio"),
16    not(feature = "neon")
17))]
18pub use ntex_compio::{from_unix_stream, unix_connect};
19
20#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
21mod no_rt {
22    use ntex_io::Io;
23    use ntex_service::cfg::SharedCfg;
24
25    /// Opens a TCP connection to a remote host.
26    pub async fn tcp_connect(_: std::net::SocketAddr, _: SharedCfg) -> std::io::Result<Io> {
27        Err(std::io::Error::other("runtime is not configure"))
28    }
29
30    #[cfg(unix)]
31    /// Opens a unix stream connection.
32    pub async fn unix_connect<'a, P>(_: P, _: SharedCfg) -> std::io::Result<Io>
33    where
34        P: AsRef<std::path::Path> + 'a,
35    {
36        Err(std::io::Error::other("runtime is not configure"))
37    }
38
39    /// Convert std TcpStream to tokio's TcpStream
40    pub fn from_tcp_stream(_: std::net::TcpStream, _: SharedCfg) -> std::io::Result<Io> {
41        Err(std::io::Error::other("runtime is not configure"))
42    }
43
44    #[cfg(unix)]
45    /// Convert std UnixStream to tokio's UnixStream
46    pub fn from_unix_stream(
47        _: std::os::unix::net::UnixStream,
48        _: SharedCfg,
49    ) -> std::io::Result<Io> {
50        Err(std::io::Error::other("runtime is not configure"))
51    }
52}
53
54#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
55pub use no_rt::*;