feat(API): Use mio::Token based polling

Avoid polling every single IO source to collect events,
poll those specific IO sources mio tells us about.
This commit is contained in:
Karolin Varner
2024-08-18 21:19:44 +02:00
parent 53e560191f
commit 77760d71df
13 changed files with 403 additions and 98 deletions

View File

@@ -141,6 +141,7 @@ fn api_integration_api_setup() -> anyhow::Result<()> {
peer_b.config_file_path.to_str().context("")?,
])
.stdin(Stdio::null())
.stderr(Stdio::null())
.stdout(Stdio::piped())
.spawn()?;

View File

@@ -293,6 +293,7 @@ struct MockBrokerInner {
#[derive(Debug, Default)]
struct MockBroker {
inner: Arc<Mutex<MockBrokerInner>>,
mio_token: Option<mio::Token>,
}
impl WireguardBrokerMio for MockBroker {
@@ -301,8 +302,9 @@ impl WireguardBrokerMio for MockBroker {
fn register(
&mut self,
_registry: &mio::Registry,
_token: mio::Token,
token: mio::Token,
) -> Result<(), Self::MioError> {
self.mio_token = Some(token);
Ok(())
}
@@ -311,8 +313,13 @@ impl WireguardBrokerMio for MockBroker {
}
fn unregister(&mut self, _registry: &mio::Registry) -> Result<(), Self::MioError> {
self.mio_token = None;
Ok(())
}
fn mio_token(&self) -> Option<mio::Token> {
self.mio_token
}
}
impl rosenpass_wireguard_broker::WireGuardBroker for MockBroker {