ntex_net/
compat.rs

1//! Utility for async runtime abstraction
2
3#[cfg(feature = "tokio")]
4pub use ntex_tokio::{from_tcp_stream, tcp_connect, tcp_connect_in};
5
6#[cfg(all(unix, feature = "tokio"))]
7pub use ntex_tokio::{from_unix_stream, unix_connect, unix_connect_in};
8
9#[cfg(all(feature = "compio", not(feature = "tokio"), not(feature = "neon")))]
10pub use ntex_compio::{from_tcp_stream, tcp_connect, tcp_connect_in};
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, unix_connect_in};
19
20#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
21mod no_rt {
22    use ntex_io::Io;
23
24    /// Opens a TCP connection to a remote host.
25    pub async fn tcp_connect(_: std::net::SocketAddr) -> std::io::Result<Io> {
26        Err(std::io::Error::other("runtime is not configure"))
27    }
28
29    /// Opens a TCP connection to a remote host and use specified memory pool.
30    pub async fn tcp_connect_in(
31        _: std::net::SocketAddr,
32        _: ntex_bytes::PoolRef,
33    ) -> std::io::Result<Io> {
34        Err(std::io::Error::other("runtime is not configure"))
35    }
36
37    #[cfg(unix)]
38    /// Opens a unix stream connection.
39    pub async fn unix_connect<'a, P>(_: P) -> std::io::Result<Io>
40    where
41        P: AsRef<std::path::Path> + 'a,
42    {
43        Err(std::io::Error::other("runtime is not configure"))
44    }
45
46    #[cfg(unix)]
47    /// Opens a unix stream connection and specified memory pool.
48    pub async fn unix_connect_in<'a, P>(_: P, _: ntex_bytes::PoolRef) -> std::io::Result<Io>
49    where
50        P: AsRef<std::path::Path> + 'a,
51    {
52        Err(std::io::Error::other("runtime is not configure"))
53    }
54
55    /// Convert std TcpStream to tokio's TcpStream
56    pub fn from_tcp_stream(_: std::net::TcpStream) -> std::io::Result<Io> {
57        Err(std::io::Error::other("runtime is not configure"))
58    }
59
60    #[cfg(unix)]
61    /// Convert std UnixStream to tokio's UnixStream
62    pub fn from_unix_stream(_: std::os::unix::net::UnixStream) -> std::io::Result<Io> {
63        Err(std::io::Error::other("runtime is not configure"))
64    }
65}
66
67#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
68pub use no_rt::*;