From ab5fb624b7ebf14dd319c7025e3658527abfb69a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 13 Mar 2025 17:42:59 +0500 Subject: [PATCH] Use new values api (#521) --- Cargo.toml | 3 ++- ntex-net/src/rt_polling/connect.rs | 32 ++++++++++--------------- ntex-net/src/rt_polling/driver.rs | 34 +++++++++++--------------- ntex-net/src/rt_uring/connect.rs | 27 ++++++++------------- ntex-net/src/rt_uring/driver.rs | 38 +++++++++++++----------------- 5 files changed, 55 insertions(+), 79 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1224f10f..e2edf0af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,8 @@ ntex-util = { path = "ntex-util" } ntex-compio = { path = "ntex-compio" } ntex-tokio = { path = "ntex-tokio" } -ntex-neon = { git = "https://github.com/ntex-rs/neon.git" } +#ntex-neon = { git = "https://github.com/ntex-rs/neon.git" } +#ntex-neon = { path = "../dev/neon" } [workspace.dependencies] async-task = "4.5.0" diff --git a/ntex-net/src/rt_polling/connect.rs b/ntex-net/src/rt_polling/connect.rs index 140004ba..1cadee97 100644 --- a/ntex-net/src/rt_polling/connect.rs +++ b/ntex-net/src/rt_polling/connect.rs @@ -90,27 +90,21 @@ struct ConnectOpsInner { impl ConnectOps { pub(crate) fn current() -> Self { - Runtime::with_current(|rt| { - if let Some(s) = rt.get::() { - s - } else { - let mut inner = None; - rt.driver().register(|api| { - let ops = Rc::new(ConnectOpsInner { - api, - connects: RefCell::new(Slab::new()), - }); - inner = Some(ops.clone()); - Box::new(ConnectOpsBatcher { - inner: ops, - feed: VecDeque::new(), - }) + Runtime::value(|rt| { + let mut inner = None; + rt.driver().register(|api| { + let ops = Rc::new(ConnectOpsInner { + api, + connects: RefCell::new(Slab::new()), }); + inner = Some(ops.clone()); + Box::new(ConnectOpsBatcher { + inner: ops, + feed: VecDeque::new(), + }) + }); - let s = ConnectOps(inner.unwrap()); - rt.insert(s.clone()); - s - } + ConnectOps(inner.unwrap()) }) } diff --git a/ntex-net/src/rt_polling/driver.rs b/ntex-net/src/rt_polling/driver.rs index 423d1d71..14fe868e 100644 --- a/ntex-net/src/rt_polling/driver.rs +++ b/ntex-net/src/rt_polling/driver.rs @@ -52,28 +52,22 @@ struct StreamOpsInner { impl StreamOps { pub(crate) fn current() -> Self { - Runtime::with_current(|rt| { - if let Some(s) = rt.get::() { - s - } else { - let mut inner = None; - rt.driver().register(|api| { - let ops = Rc::new(StreamOpsInner { - api, - feed: Cell::new(Some(VecDeque::new())), - streams: Cell::new(Some(Box::new(Slab::new()))), - }); - inner = Some(ops.clone()); - Box::new(StreamOpsHandler { - inner: ops, - feed: VecDeque::new(), - }) + Runtime::value(|rt| { + let mut inner = None; + rt.driver().register(|api| { + let ops = Rc::new(StreamOpsInner { + api, + feed: Cell::new(Some(VecDeque::new())), + streams: Cell::new(Some(Box::new(Slab::new()))), }); + inner = Some(ops.clone()); + Box::new(StreamOpsHandler { + inner: ops, + feed: VecDeque::new(), + }) + }); - let s = StreamOps(inner.unwrap()); - rt.insert(s.clone()); - s - } + StreamOps(inner.unwrap()) }) } diff --git a/ntex-net/src/rt_uring/connect.rs b/ntex-net/src/rt_uring/connect.rs index eba482ad..3bec714f 100644 --- a/ntex-net/src/rt_uring/connect.rs +++ b/ntex-net/src/rt_uring/connect.rs @@ -85,24 +85,17 @@ struct ConnectOpsInner { impl ConnectOps { pub(crate) fn current() -> Self { - Runtime::with_current(|rt| { - if let Some(s) = rt.get::() { - s - } else { - let mut inner = None; - rt.driver().register(|api| { - let ops = Rc::new(ConnectOpsInner { - api, - ops: RefCell::new(Slab::new()), - }); - inner = Some(ops.clone()); - Box::new(ConnectOpsHandler { inner: ops }) + Runtime::value(|rt| { + let mut inner = None; + rt.driver().register(|api| { + let ops = Rc::new(ConnectOpsInner { + api, + ops: RefCell::new(Slab::new()), }); - - let s = ConnectOps(inner.unwrap()); - rt.insert(s.clone()); - s - } + inner = Some(ops.clone()); + Box::new(ConnectOpsHandler { inner: ops }) + }); + ConnectOps(inner.unwrap()) }) } diff --git a/ntex-net/src/rt_uring/driver.rs b/ntex-net/src/rt_uring/driver.rs index e6aeef85..dbf2160f 100644 --- a/ntex-net/src/rt_uring/driver.rs +++ b/ntex-net/src/rt_uring/driver.rs @@ -59,31 +59,25 @@ struct StreamOpsStorage { impl StreamOps { pub(crate) fn current() -> Self { - Runtime::with_current(|rt| { - if let Some(s) = rt.get::() { - s - } else { - let mut inner = None; - rt.driver().register(|api| { - let mut ops = Slab::new(); - ops.insert(Operation::Nop); + Runtime::value(|rt| { + let mut inner = None; + rt.driver().register(|api| { + let mut ops = Slab::new(); + ops.insert(Operation::Nop); - let ops = Rc::new(StreamOpsInner { - api, - feed: RefCell::new(Vec::new()), - storage: RefCell::new(StreamOpsStorage { - ops, - streams: Slab::new(), - }), - }); - inner = Some(ops.clone()); - Box::new(StreamOpsHandler { inner: ops }) + let ops = Rc::new(StreamOpsInner { + api, + feed: RefCell::new(Vec::new()), + storage: RefCell::new(StreamOpsStorage { + ops, + streams: Slab::new(), + }), }); + inner = Some(ops.clone()); + Box::new(StreamOpsHandler { inner: ops }) + }); - let s = StreamOps(inner.unwrap()); - rt.insert(s.clone()); - s - } + StreamOps(inner.unwrap()) }) }