diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-18 12:35:38 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-18 12:35:38 +0100 |
commit | d19fda8ff4003113c9760189808293594f856a91 (patch) | |
tree | a544ef3efeb55c315cbb9829c4ecb112ff4174b2 /src/connection.rs | |
parent | 2c20dc2932696cb87ea7e6eb5327b7dccf0e9b1b (diff) |
ensure rtnetlink handle is not dropped before reading reply by wrapping it0.4.0
Diffstat (limited to 'src/connection.rs')
-rw-r--r-- | src/connection.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/connection.rs b/src/connection.rs new file mode 100644 index 0000000..37d31f4 --- /dev/null +++ b/src/connection.rs @@ -0,0 +1,23 @@ +use crate::Result; + +use rtnetlink::Handle; + +#[derive(Debug)] +pub struct Connection(Handle); + +impl Connection { + /// Creates a new connection and handle to rtnetlink and spawns the connection task. + /// Can be used to interact with rtnetlink by enabling certain crate features + /// and calling the methods they provide. + pub fn new() -> Result<Self> { + let (conn, handle, _) = rtnetlink::new_connection()?; + tokio::spawn(conn); + + Ok(Self(handle)) + } + + /// Returns a reference to the underlying [`rtnetlink::Handle`]. + pub(crate) fn handle(&self) -> &Handle { + &self.0 + } +} |