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;
19
20#[cfg(all(feature = "compio", not(feature = "tokio"), not(feature = "neon")))]
21pub use ntex_compio::unix_connect;
22
23#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
24mod no_rt {
25    use ntex_io::Io;
26    use ntex_service::cfg::SharedCfg;
27
28    /// Opens a TCP connection to a remote host.
29    pub async fn tcp_connect(_: std::net::SocketAddr, _: SharedCfg) -> std::io::Result<Io> {
30        Err(std::io::Error::other("runtime is not configure"))
31    }
32
33    #[cfg(unix)]
34    /// Opens a unix stream connection.
35    pub async fn unix_connect<'a, P>(_: P, _: SharedCfg) -> std::io::Result<Io>
36    where
37        P: AsRef<std::path::Path> + 'a,
38    {
39        Err(std::io::Error::other("runtime is not configure"))
40    }
41
42    /// Convert std TcpStream to tokio's TcpStream
43    pub fn from_tcp_stream(_: std::net::TcpStream, _: SharedCfg) -> std::io::Result<Io> {
44        Err(std::io::Error::other("runtime is not configure"))
45    }
46
47    #[cfg(unix)]
48    /// Convert std UnixStream to tokio's UnixStream
49    pub fn from_unix_stream(
50        _: std::os::unix::net::UnixStream,
51        _: SharedCfg,
52    ) -> std::io::Result<Io> {
53        Err(std::io::Error::other("runtime is not configure"))
54    }
55}
56
57#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
58pub use no_rt::*;