Skip to main content

dope_core/driver/
control.rs

1use std::io;
2use std::os::fd::BorrowedFd;
3
4use crate::backend::Backend;
5use crate::backend::ops::raw::control::ControlBackend;
6use crate::io::fd::Fd;
7use crate::io::socket::option::SocketOption;
8
9use super::token::Token;
10use super::{DriverContext, OutboundReservation, PushError};
11
12pub trait ContextControl {
13    fn prepare_drop(&mut self);
14    fn register_shutdown_fd(&mut self, fd: BorrowedFd<'_>) -> io::Result<()>;
15    fn reserve_outbound(&mut self, count: u32) -> io::Result<OutboundReservation>;
16    fn reserve_route(&mut self, id: u8) -> bool;
17    fn release_route(&mut self, id: u8);
18    fn poison_route(&mut self, id: u8);
19    fn quiesce(&mut self, targets: &[Token]) -> bool;
20    /// Queues an option without waiting for its kernel completion.
21    fn submit_option(
22        &mut self,
23        fd: &Fd<'_>,
24        option: impl Into<SocketOption>,
25    ) -> Result<(), PushError>;
26}
27
28impl ContextControl for DriverContext<'_, '_> {
29    fn prepare_drop(&mut self) {
30        <Backend as ControlBackend>::prepare_drop(self.backend());
31    }
32
33    fn register_shutdown_fd(&mut self, fd: BorrowedFd<'_>) -> io::Result<()> {
34        <Backend as ControlBackend>::register_shutdown_fd(self.backend(), fd)
35    }
36
37    fn reserve_outbound(&mut self, count: u32) -> io::Result<OutboundReservation> {
38        <Backend as ControlBackend>::reserve_outbound(self.backend(), count)
39    }
40
41    fn reserve_route(&mut self, id: u8) -> bool {
42        <Backend as ControlBackend>::reserve_route(self.backend(), id)
43    }
44
45    fn release_route(&mut self, id: u8) {
46        <Backend as ControlBackend>::release_route(self.backend(), id);
47    }
48
49    fn poison_route(&mut self, id: u8) {
50        <Backend as ControlBackend>::poison_route(self.backend(), id);
51    }
52
53    fn quiesce(&mut self, targets: &[Token]) -> bool {
54        <Backend as ControlBackend>::quiesce(self.backend(), targets)
55    }
56
57    fn submit_option(
58        &mut self,
59        fd: &Fd<'_>,
60        option: impl Into<SocketOption>,
61    ) -> Result<(), PushError> {
62        let option = option.into();
63        <Backend as ControlBackend>::submit_option(
64            self.backend(),
65            fd.slot(),
66            option.level(),
67            option.name(),
68            option.value(),
69        )
70    }
71}