Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Mar 23, 2024
1 parent d393d87 commit 6c56aef
Show file tree
Hide file tree
Showing 24 changed files with 228 additions and 187 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"ntex-http",
"ntex-router",
"ntex-rt",
"ntex-net",
"ntex-server",
"ntex-service",
"ntex-tls",
Expand All @@ -25,6 +26,7 @@ ntex-bytes = { path = "ntex-bytes" }
ntex-codec = { path = "ntex-codec" }
ntex-connect = { path = "ntex-connect" }
ntex-io = { path = "ntex-io" }
ntex-net = { path = "ntex-net" }
ntex-http = { path = "ntex-http" }
ntex-router = { path = "ntex-router" }
ntex-rt = { path = "ntex-rt" }
Expand Down
1 change: 0 additions & 1 deletion ntex-async-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ ntex-bytes = "0.1.21"
ntex-io = "1.0.0"
ntex-util = "1.0.0"
log = "0.4"
pin-project-lite = "0.2"
async-std = { version = "1", features = ["unstable"] }
oneshot = { version = "0.1", default-features = false, features = ["async"] }
13 changes: 5 additions & 8 deletions ntex-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-connect"
version = "1.0.0"
version = "1.1.0"
authors = ["ntex contributors <team@ntex.rs>"]
description = "ntexwork connect utils for ntex framework"
keywords = ["network", "framework", "async", "futures"]
Expand All @@ -25,13 +25,13 @@ openssl = ["tls-openssl", "ntex-tls/openssl"]
rustls = ["tls-rustls", "webpki-roots", "ntex-tls/rustls"]

# tokio runtime
tokio = ["ntex-rt/tokio", "ntex-tokio"]
tokio = []

# glommio runtime
glommio = ["ntex-rt/glommio", "ntex-glommio"]
glommio = []

# async-std runtime
async-std = ["ntex-rt/async-std", "ntex-async-std"]
async-std = []

[dependencies]
ntex-service = "2.0.0"
Expand All @@ -41,14 +41,11 @@ ntex-util = "1.0.0"
ntex-bytes = "0.1.21"
ntex-http = "0.1"
ntex-rt = "0.4.7"
ntex-net = "1.0.0"

log = "0.4"
thiserror = "1.0"

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 }

# openssl
tls-openssl = { version="0.10", package = "openssl", optional = true }

Expand Down
109 changes: 1 addition & 108 deletions ntex-connect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,112 +32,5 @@ where
#[allow(unused_imports)]
#[doc(hidden)]
pub mod net {
use super::*;

#[cfg(feature = "tokio")]
pub use ntex_tokio::*;

#[cfg(all(
feature = "async-std",
not(feature = "tokio"),
not(feature = "glommio")
))]
pub use ntex_async_std::*;

#[cfg(all(
feature = "glommio",
not(feature = "tokio"),
not(feature = "async-std")
))]
pub use ntex_glommio::*;

#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "glommio")
))]
/// 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",
))
}

#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "glommio")
))]
/// 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)]
#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "glommio")
))]
/// 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)]
#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "glommio")
))]
/// 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",
))
}

#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "glommio")
))]
/// 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)]
#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "glommio")
))]
/// 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",
))
}
pub use ntex_net::*;
}
5 changes: 5 additions & 0 deletions ntex-net/CHANGES.md
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
37 changes: 37 additions & 0 deletions ntex-net/Cargo.toml
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 }
1 change: 1 addition & 0 deletions ntex-net/LICENSE-APACHE
1 change: 1 addition & 0 deletions ntex-net/LICENSE-MIT
117 changes: 117 additions & 0 deletions ntex-net/src/lib.rs
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::*;
7 changes: 5 additions & 2 deletions ntex-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-server"
version = "0.1.0"
version = "1.0.0"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Server for ntex framework"
keywords = ["network", "framework", "async", "futures"]
Expand All @@ -16,14 +16,17 @@ name = "ntex_server"
path = "src/lib.rs"

[dependencies]
ntex-bytes = "0.1"
ntex-bytes = "0.1.24"
ntex-net = "1.0"
ntex-service = "2.0"
ntex-rt = "0.4"
ntex-util = "1.0"

async-channel = "2.2"
async-broadcast = "0.7"
polling = "3.3"
log = "0.4"
socket2 = "0.5"
oneshot = { version = "0.1", default-features = false, features = ["async"] }

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion ntex-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)]
#![deny(rust_2018_idioms, unreachable_pub)]
#![allow(clippy::let_underscore_future)]

use ntex_service::ServiceFactory;
use ntex_util::time::Millis;

mod manager;
pub mod net;
mod pool;
mod server;
mod signals;
Expand Down
Loading

0 comments on commit 6c56aef

Please sign in to comment.