This commit is contained in:
Nikolay Kim 2025-03-10 11:39:34 +05:00
parent 57dab15e4d
commit d1a09bbb21
19 changed files with 47 additions and 70 deletions

View file

@ -29,11 +29,13 @@ targets = [
[dependencies]
async-task = { workspace = true }
bitflags = { workspace = true }
cfg-if = { workspace = true }
crossbeam-queue = { workspace = true }
scoped-tls = { workspace = true }
fxhash = { workspace = true }
nohash-hasher = { workspace = true }
log = { workspace = true }
scoped-tls = { workspace = true }
socket2 = { workspace = true, features = ["all"] }
# Windows specific dependencies

View file

@ -1,6 +1,6 @@
use std::{io, marker::PhantomData, mem::MaybeUninit, pin::Pin, task::Waker};
use crate::{OpCode, Overlapped, PushEntry, RawFd};
use super::{OpCode, Overlapped, PushEntry, RawFd};
/// An operation with other needed information. It should be allocated on the
/// heap. The pointer to this struct is used as `user_data`, and on Windows, it

View file

@ -134,14 +134,14 @@ macro_rules! syscall {
#[doc(hidden)]
macro_rules! impl_raw_fd {
($t:ty, $it:ty, $inner:ident) => {
impl $crate::AsRawFd for $t {
fn as_raw_fd(&self) -> $crate::RawFd {
impl $crate::driver::AsRawFd for $t {
fn as_raw_fd(&self) -> $crate::driver::RawFd {
self.$inner.as_raw_fd()
}
}
#[cfg(unix)]
impl std::os::fd::FromRawFd for $t {
unsafe fn from_raw_fd(fd: $crate::RawFd) -> Self {
unsafe fn from_raw_fd(fd: $crate::driver::RawFd) -> Self {
Self {
$inner: std::os::fd::FromRawFd::from_raw_fd(fd),
}

View file

@ -7,9 +7,9 @@
use std::{io, marker::PhantomPinned, mem::ManuallyDrop, net::Shutdown};
#[cfg(unix)]
pub use crate::sys::op::{CreateSocket, Interest};
pub use super::sys::op::{CreateSocket, Interest};
use crate::OwnedFd;
use super::OwnedFd;
pub trait Handler {
/// Submitted interest

View file

@ -8,7 +8,9 @@ use crossbeam_queue::SegQueue;
use nohash_hasher::IntMap;
use polling::{Event, Events, Poller};
use crate::{op::Handler, op::Interest, AsyncifyPool, Entry, Key, ProactorBuilder};
use crate::driver::{
op::Handler, op::Interest, sys, AsyncifyPool, Entry, Key, ProactorBuilder,
};
pub(crate) mod op;
@ -228,7 +230,7 @@ impl Driver {
self.handlers.set(Some(handlers));
}
pub fn create_op<T: crate::sys::OpCode + 'static>(&self, op: T) -> Key<T> {
pub fn create_op<T: sys::OpCode + 'static>(&self, op: T) -> Key<T> {
Key::new(self.as_raw_fd(), op)
}
@ -236,7 +238,7 @@ impl Driver {
Ok(())
}
pub fn push(&self, op: &mut Key<dyn crate::sys::OpCode>) -> Poll<io::Result<usize>> {
pub fn push(&self, op: &mut Key<dyn sys::OpCode>) -> Poll<io::Result<usize>> {
let user_data = op.user_data();
let op_pin = op.as_op_pin();
match op_pin.pre_submit()? {
@ -390,7 +392,7 @@ impl Driver {
let poll = self.poll.clone();
let completed = self.pool_completed.clone();
let mut closure = move || {
let mut op = unsafe { Key::<dyn crate::sys::OpCode>::new_unchecked(user_data) };
let mut op = unsafe { Key::<dyn sys::OpCode>::new_unchecked(user_data) };
let op_pin = op.as_op_pin();
let res = match op_pin.operate() {
Poll::Pending => unreachable!("this operation is not non-blocking"),

View file

@ -1,9 +1,9 @@
use std::{io, marker::Send, os::fd::FromRawFd, os::fd::RawFd, pin::Pin, task::Poll};
pub use crate::unix::op::*;
pub use crate::driver::unix::op::*;
use super::{AsRawFd, Decision, OpCode};
use crate::{op::*, syscall};
use crate::{driver::op::*, syscall};
impl<D, F> OpCode for Asyncify<F, D>
where

View file

@ -3,7 +3,7 @@
pub(crate) mod op;
use crate::RawFd;
use crate::driver::RawFd;
/// The overlapped struct for unix needn't contain extra fields.
pub(crate) struct Overlapped;

View file

@ -1,6 +1,6 @@
use std::net::Shutdown;
use crate::op::*;
use crate::driver::op::*;
/// The interest to poll a file descriptor.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

View file

@ -3,7 +3,8 @@ use std::{future::Future, io, mem, mem::MaybeUninit};
use socket2::{Domain, Protocol, SockAddr, Socket as Socket2, Type};
use crate::driver::{impl_raw_fd, op::CloseSocket, op::ShutdownSocket, syscall, AsRawFd};
use crate::driver::{op::CloseSocket, op::ShutdownSocket, AsRawFd};
use crate::{impl_raw_fd, syscall};
#[derive(Debug)]
pub struct Socket {

View file

@ -2,7 +2,7 @@ use std::{future::Future, io, net::SocketAddr};
use socket2::Socket as Socket2;
use crate::{driver::impl_raw_fd, net::Socket};
use crate::{impl_raw_fd, net::Socket};
/// A TCP stream between a local and a remote socket.
///

View file

@ -2,7 +2,7 @@ use std::{future::Future, io};
use socket2::{SockAddr, Socket as Socket2};
use crate::{driver::impl_raw_fd, net::Socket};
use crate::{impl_raw_fd, net::Socket};
/// A Unix stream between two local sockets on Windows & WSL.
///

View file

@ -86,14 +86,14 @@ impl Runtime {
/// This method will panic if there are no running [`Runtime`].
pub fn with_current<T, F: FnOnce(&Self) -> T>(f: F) -> T {
#[cold]
fn not_in_ntex_runtime() -> ! {
panic!("not in a ntex runtime")
fn not_in_neon_runtime() -> ! {
panic!("not in a neon runtime")
}
if CURRENT_RUNTIME.is_set() {
CURRENT_RUNTIME.with(f)
} else {
not_in_ntex_runtime()
not_in_neon_runtime()
}
}

View file

@ -6,36 +6,24 @@ 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 = "default-rt",
not(feature = "tokio"),
not(feature = "compio")
))]
#[cfg(all(feature = "neon", not(feature = "tokio"), not(feature = "compio")))]
pub use crate::rt::{
from_tcp_stream, from_unix_stream, tcp_connect, tcp_connect_in, unix_connect,
unix_connect_in,
};
#[cfg(all(
feature = "compio",
not(feature = "tokio"),
not(feature = "default-rt")
))]
#[cfg(all(feature = "compio", not(feature = "tokio"), not(feature = "neon")))]
pub use ntex_compio::{from_tcp_stream, tcp_connect, tcp_connect_in};
#[cfg(all(
unix,
feature = "compio",
not(feature = "tokio"),
not(feature = "default-rt")
not(feature = "neon")
))]
pub use ntex_compio::{from_unix_stream, unix_connect, unix_connect_in};
#[cfg(all(
not(feature = "tokio"),
not(feature = "compio"),
not(feature = "default-rt")
))]
#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
mod no_rt {
use ntex_io::Io;
@ -100,9 +88,5 @@ mod no_rt {
}
}
#[cfg(all(
not(feature = "tokio"),
not(feature = "compio"),
not(feature = "default-rt")
))]
#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
pub use no_rt::*;

View file

@ -9,9 +9,5 @@ pub use ntex_rt::{spawn, spawn_blocking};
pub use self::compat::*;
#[cfg(all(
feature = "default-rt",
not(feature = "tokio"),
not(feature = "compio")
))]
#[cfg(all(feature = "neon", not(feature = "tokio"), not(feature = "compio")))]
mod rt;

View file

@ -2,9 +2,9 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use std::{cell::RefCell, collections::VecDeque, io, path::Path, rc::Rc, task::Poll};
use ntex_neon::driver::op::{Handler, Interest};
use ntex_neon::driver::{syscall, AsRawFd, DriverApi, RawFd};
use ntex_neon::driver::{AsRawFd, DriverApi, RawFd};
use ntex_neon::net::{Socket, TcpStream, UnixStream};
use ntex_neon::Runtime;
use ntex_neon::{syscall, Runtime};
use ntex_util::channel::oneshot::{channel, Sender};
use slab::Slab;
use socket2::{Protocol, SockAddr, Type};

View file

@ -1,8 +1,8 @@
use std::{cell::Cell, collections::VecDeque, fmt, io, ptr, rc::Rc, task, task::Poll};
use ntex_neon::driver::op::{Handler, Interest};
use ntex_neon::driver::{syscall, AsRawFd, DriverApi, RawFd};
use ntex_neon::Runtime;
use ntex_neon::driver::{AsRawFd, DriverApi, RawFd};
use ntex_neon::{syscall, Runtime};
use slab::Slab;
use ntex_bytes::BufMut;

View file

@ -3,7 +3,7 @@ use std::{any, future::poll_fn, io, task::Poll};
use ntex_io::{
types, Handle, IoContext, IoStream, ReadContext, ReadStatus, WriteContext, WriteStatus,
};
use ntex_runtime::{net::TcpStream, net::UnixStream, spawn};
use ntex_neon::{net::TcpStream, net::UnixStream, spawn};
use super::driver::{Closable, CompioOps, StreamCtl};

View file

@ -47,14 +47,14 @@ where
/// Convert std TcpStream to tokio's TcpStream
pub fn from_tcp_stream(stream: net::TcpStream) -> Result<Io> {
stream.set_nodelay(true)?;
Ok(Io::new(TcpStream(ntex_runtime::net::TcpStream::from_std(
Ok(Io::new(TcpStream(ntex_neon::net::TcpStream::from_std(
stream,
)?)))
}
/// Convert std UnixStream to tokio's UnixStream
pub fn from_unix_stream(stream: std::os::unix::net::UnixStream) -> Result<Io> {
Ok(Io::new(UnixStream(
ntex_runtime::net::UnixStream::from_std(stream)?,
)))
Ok(Io::new(UnixStream(ntex_neon::net::UnixStream::from_std(
stream,
)?)))
}

View file

@ -248,8 +248,8 @@ mod compio {
}
#[allow(dead_code)]
#[cfg(feature = "default-rt")]
mod default_rt {
#[cfg(feature = "neon")]
mod neon {
use std::task::{ready, Context, Poll};
use std::{fmt, future::poll_fn, future::Future, pin::Pin};
@ -408,15 +408,11 @@ pub use self::tokio::*;
#[cfg(feature = "compio")]
pub use self::compio::*;
#[cfg(feature = "default-rt")]
pub use self::default_rt::*;
#[cfg(feature = "neon")]
pub use self::neon::*;
#[allow(dead_code)]
#[cfg(all(
not(feature = "tokio"),
not(feature = "compio"),
not(feature = "default-rt")
))]
#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
mod no_rt {
use std::task::{Context, Poll};
use std::{fmt, future::Future, marker::PhantomData, pin::Pin};
@ -475,9 +471,5 @@ mod no_rt {
impl std::error::Error for JoinError {}
}
#[cfg(all(
not(feature = "tokio"),
not(feature = "compio"),
not(feature = "default-rt")
))]
#[cfg(all(not(feature = "tokio"), not(feature = "compio"), not(feature = "neon")))]
pub use self::no_rt::*;