aboutsummaryrefslogtreecommitdiff
path: root/src/connection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/connection.rs')
-rw-r--r--src/connection.rs23
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
+ }
+}