diff --git a/src/connection.rs b/src/connection.rs index 6cc99f6..6310a28 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -50,6 +50,13 @@ where Option, SocketAddr)>>, socket_closed: bool, + + /// Whether [NetlinkPayload::Noop] should forwared to handler + forward_noop: bool, + /// Whether [NetlinkPayload::Done] should forwared to handler + forward_done: bool, + /// Whether [NetlinkPayload::Ack] should forwared to handler + forward_ack: bool, } impl Connection @@ -73,9 +80,24 @@ where requests_rx: Some(requests_rx), unsolicited_messages_tx: Some(unsolicited_messages_tx), socket_closed: false, + forward_noop: false, + forward_done: false, + forward_ack: false, }) } + pub fn set_forward_noop(&mut self, value: bool) { + self.forward_noop = value; + } + + pub fn set_forward_done(&mut self, value: bool) { + self.forward_done = value; + } + + pub fn set_forward_ack(&mut self, value: bool) { + self.forward_ack = value; + } + pub fn socket_mut(&mut self) -> &mut S { self.socket.get_mut() } @@ -242,6 +264,12 @@ where if done { use NetlinkPayload::*; match &message.payload { + Noop => { + if !self.forward_noop { + trace!("Not forwarding Noop message to the handle"); + continue; + } + } // Since `self.protocol` set the `done` flag here, // we know it has already dropped the request and // its associated metadata, ie the UnboundedSender @@ -250,12 +278,11 @@ where // dropping the last instance of that sender, // hence closing the channel and signaling the // handle that no more messages are expected. - Noop | Done(_) => { - trace!( - "not forwarding Noop/Ack/Done message to \ - the handle" - ); - continue; + Done(_) => { + if !self.forward_done { + trace!("Not forwarding Done message to the handle"); + continue; + } } // I'm not sure how we should handle overrun messages Overrun(_) => unimplemented!("overrun is not handled yet"), @@ -264,11 +291,8 @@ where // because only the user knows how they want to // handle them. Error(err_msg) => { - if err_msg.code.is_none() { - trace!( - "not forwarding Noop/Ack/Done message to \ - the handle" - ); + if err_msg.code.is_none() && !self.forward_ack { + trace!("Not forwarding Ack message to the handle"); continue; } }