forked from smoltcp-rs/smoltcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kill switch workaround around rx-queue saturation
Uses a kill switch work around, which disables rx to avoid any potential errors while receiving, thus allowing the egress part of the poll loop to actually perform uninterrupted work. This is a hack, and should be regarded as a a temporary, potentially buggy solution. Copy with care.
- Loading branch information
1 parent
4c50499
commit dc2a9af
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use std::rc::Rc; | ||
use std::cell::RefCell; | ||
|
||
use super::{Device, DeviceCapabilities}; | ||
|
||
pub struct KillSwitch<P> { | ||
inner: P, | ||
switch: Rc<RefCell<Config>>, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Switch { | ||
switch: Rc<RefCell<Config>>, | ||
} | ||
|
||
#[derive(Default)] | ||
struct Config { | ||
no_rx: bool, | ||
no_tx: bool, | ||
} | ||
|
||
impl<P> KillSwitch<P> { | ||
pub fn new(device: P) -> Self { | ||
KillSwitch { | ||
inner: device, | ||
switch: Rc::default(), | ||
} | ||
} | ||
|
||
pub fn switch(&self) -> Switch { | ||
Switch { | ||
switch: self.switch.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl Switch { | ||
pub fn kill_rx(&self, killed: bool) -> bool { | ||
core::mem::replace(&mut self.switch.borrow_mut().no_rx, killed) | ||
} | ||
|
||
pub fn kill_tx(&self, killed: bool) -> bool { | ||
core::mem::replace(&mut self.switch.borrow_mut().no_tx, killed) | ||
} | ||
} | ||
|
||
impl<'a, P> Device<'a> for KillSwitch<P> | ||
where P: Device<'a> | ||
{ | ||
type RxToken = P::RxToken; | ||
type TxToken = P::TxToken; | ||
|
||
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { | ||
if self.switch.borrow().no_rx { | ||
None | ||
} else { | ||
self.inner.receive() | ||
} | ||
} | ||
|
||
fn transmit(&'a mut self) -> Option<Self::TxToken> { | ||
if self.switch.borrow().no_tx { | ||
None | ||
} else { | ||
self.inner.transmit() | ||
} | ||
} | ||
|
||
fn capabilities(&self) -> DeviceCapabilities { | ||
self.inner.capabilities() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters