aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-11-18 14:21:39 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-11-18 14:21:39 +0100
commitb37c7a2b7692a4f8aa57865df4c00de07a5666dc (patch)
tree15fb2144aba5d561b74f4ab5bde1396e5e799eeb
parent526c694bcdb08da99aab6da308775fe5e0164b95 (diff)
blocking: spawn connection task and actual requests in the same runtime0.4.4
-rw-r--r--Cargo.toml2
-rw-r--r--src/blocking.rs24
2 files changed, 16 insertions, 10 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 976410b..105a20c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rsdsl_netlinklib"
-version = "0.4.3"
+version = "0.4.4"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/blocking.rs b/src/blocking.rs
index a60fa7c..1e80a30 100644
--- a/src/blocking.rs
+++ b/src/blocking.rs
@@ -11,31 +11,37 @@ pub use crate::tunnel;
/// A blocking wrapper around the async [`crate::Connection`].
#[derive(Debug)]
-pub struct Connection(crate::Connection);
+pub struct Connection {
+ rt: tokio::runtime::Runtime,
+ conn: crate::Connection,
+}
impl Connection {
/// Creates a new blocking wrapper around [`crate::Connection`].
pub fn new() -> crate::Result<Self> {
- Ok(Self(
- tokio::runtime::Runtime::new()?.block_on(crate::Connection::new())?,
- ))
+ let rt = tokio::runtime::Runtime::new()?;
+
+ Ok(Self {
+ conn: rt.block_on(crate::Connection::new())?,
+ rt,
+ })
}
}
macro_rules! blockify {
($blk:ident) => {
pub fn $blk(&self) -> crate::Result<()> {
- tokio::runtime::Runtime::new()?.block_on(self.0.$blk())
+ self.rt.block_on(self.conn.$blk())
}
};
($blk:ident, $($v:tt: $t:ty),*) => {
pub fn $blk(&self, $($v: $t),*) -> crate::Result<()> {
- tokio::runtime::Runtime::new()?.block_on(self.0.$blk($($v),*))
+ self.rt.block_on(self.conn.$blk($($v),*))
}
};
($blk:ident -> $ret:ty, $($v:tt: $t:ty),*) => {
pub fn $blk(&self, $($v: $t),*) -> crate::Result<$ret> {
- tokio::runtime::Runtime::new()?.block_on(self.0.$blk($($v),*))
+ self.rt.block_on(self.conn.$blk($($v),*))
}
};
}
@@ -57,8 +63,8 @@ pub mod addr {
blockify!(address_add_link_local, link: String, addr: IpAddr, prefix_len: u8);
pub fn address_get(&self, link: String) -> crate::Result<Vec<IpAddr>> {
- tokio::runtime::Runtime::new()?
- .block_on(async { self.0.address_get(link).await?.try_collect().await })
+ self.rt
+ .block_on(async { self.conn.address_get(link).await?.try_collect().await })
}
}
}