-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
228 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changes | ||
|
||
## [1.0.0] - 2024-03-23 | ||
|
||
* Move to separate crate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "ntex-net" | ||
version = "1.0.0" | ||
authors = ["ntex contributors <team@ntex.rs>"] | ||
description = "ntexwork utils for ntex framework" | ||
keywords = ["network", "framework", "async", "futures"] | ||
homepage = "https://ntex.rs" | ||
repository = "https://github.com/ntex-rs/ntex.git" | ||
documentation = "https://docs.rs/ntex-connect/" | ||
categories = ["network-programming", "asynchronous"] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "ntex_net" | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
default = [] | ||
|
||
# tokio runtime | ||
tokio = ["ntex-rt/tokio", "ntex-tokio"] | ||
|
||
# glommio runtime | ||
glommio = ["ntex-rt/glommio", "ntex-glommio"] | ||
|
||
# async-std runtime | ||
async-std = ["ntex-rt/async-std", "ntex-async-std"] | ||
|
||
[dependencies] | ||
ntex-bytes = "0.1.24" | ||
ntex-io = "1.0.0" | ||
ntex-rt = "0.4.7" | ||
|
||
ntex-tokio = { version = "0.4.0", optional = true } | ||
ntex-glommio = { version = "0.4.0", optional = true } | ||
ntex-async-std = { version = "0.4.0", optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//! Utility for async runtime abstraction | ||
#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)] | ||
|
||
pub use ntex_io::Io; | ||
pub use ntex_rt::spawn; | ||
|
||
#[cfg(feature = "tokio")] | ||
pub use ntex_tokio::{from_tcp_stream, tcp_connect, tcp_connect_in}; | ||
|
||
#[cfg(all(unix, feature = "tokio"))] | ||
pub use ntex_tokio::{from_unix_stream, unix_connect, unix_connect_in}; | ||
|
||
#[cfg(all( | ||
feature = "async-std", | ||
not(feature = "tokio"), | ||
not(feature = "glommio") | ||
))] | ||
pub use ntex_async_std::{from_tcp_stream, tcp_connect, tcp_connect_in}; | ||
|
||
#[cfg(all( | ||
unix, | ||
feature = "async-std", | ||
not(feature = "tokio"), | ||
not(feature = "glommio") | ||
))] | ||
pub use ntex_async_std::{from_unix_stream, unix_connect, unix_connect_in}; | ||
|
||
#[cfg(all( | ||
feature = "glommio", | ||
not(feature = "tokio"), | ||
not(feature = "async-std") | ||
))] | ||
pub use ntex_glommio::{from_tcp_stream, tcp_connect, tcp_connect_in}; | ||
|
||
#[cfg(all( | ||
unix, | ||
feature = "glommio", | ||
not(feature = "tokio"), | ||
not(feature = "async-std") | ||
))] | ||
pub use ntex_async_std::{from_unix_stream, unix_connect, unix_connect_in}; | ||
|
||
#[cfg(all( | ||
not(feature = "tokio"), | ||
not(feature = "async-std"), | ||
not(feature = "glommio") | ||
))] | ||
mod no_rt { | ||
use ntex_io::Io; | ||
|
||
/// Opens a TCP connection to a remote host. | ||
pub async fn tcp_connect(_: std::net::SocketAddr) -> std::io::Result<Io> { | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"runtime is not configure", | ||
)) | ||
} | ||
|
||
/// Opens a TCP connection to a remote host and use specified memory pool. | ||
pub async fn tcp_connect_in( | ||
_: std::net::SocketAddr, | ||
_: ntex_bytes::PoolRef, | ||
) -> std::io::Result<Io> { | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"runtime is not configure", | ||
)) | ||
} | ||
|
||
#[cfg(unix)] | ||
/// Opens a unix stream connection. | ||
pub async fn unix_connect<'a, P>(_: P) -> std::io::Result<Io> | ||
where | ||
P: AsRef<std::path::Path> + 'a, | ||
{ | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"runtime is not configure", | ||
)) | ||
} | ||
|
||
#[cfg(unix)] | ||
/// Opens a unix stream connection and specified memory pool. | ||
pub async fn unix_connect_in<'a, P>(_: P, _: ntex_bytes::PoolRef) -> std::io::Result<Io> | ||
where | ||
P: AsRef<std::path::Path> + 'a, | ||
{ | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"runtime is not configure", | ||
)) | ||
} | ||
|
||
/// Convert std TcpStream to tokio's TcpStream | ||
pub fn from_tcp_stream(_: std::net::TcpStream) -> std::io::Result<Io> { | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"runtime is not configure", | ||
)) | ||
} | ||
|
||
#[cfg(unix)] | ||
/// Convert std UnixStream to tokio's UnixStream | ||
pub fn from_unix_stream(_: std::os::unix::net::UnixStream) -> std::io::Result<Io> { | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"runtime is not configure", | ||
)) | ||
} | ||
} | ||
|
||
#[cfg(all( | ||
not(feature = "tokio"), | ||
not(feature = "async-std"), | ||
not(feature = "glommio") | ||
))] | ||
pub use no_rt::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.