Skip to content

Commit

Permalink
[eclipse-iceoryx#430] Fix clippy single match warning in package iceo…
Browse files Browse the repository at this point in the history
…ryx2

* the change is done by running 'cargo clippy --fix --lib -p iceoryx2'
  • Loading branch information
xieyuschen committed Oct 3, 2024
1 parent 6d25b61 commit f64ba6f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 79 deletions.
1 change: 1 addition & 0 deletions iceoryx2/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ impl<Service: service::Service> Drop for SharedNode<Service> {
}

/// The [`Node`] is the entry point to the whole iceoryx2 infrastructure and owns all entities.
///
/// As soon as a process crashes other processes can detect dead [`Node`]s via [`Node::list()`]
/// and clean up the stale resources - the entities that
/// were created via the [`Node`].
Expand Down
27 changes: 12 additions & 15 deletions iceoryx2/src/port/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,18 @@ impl<Service: service::Service> Notifier<Service> {
}

for i in 0..self.listener_connections.len() {
match self.listener_connections.get(i) {
Some(ref connection) => match connection.notifier.notify(value) {
Err(iceoryx2_cal::event::NotifierNotifyError::Disconnected) => {
self.listener_connections.remove(i);
}
Err(e) => {
warn!(from self, "Unable to send notification via connection {:?} due to {:?}.",
connection, e)
}
Ok(_) => {
number_of_triggered_listeners += 1;
}
},
None => (),
}
if let Some(ref connection) = self.listener_connections.get(i) { match connection.notifier.notify(value) {
Err(iceoryx2_cal::event::NotifierNotifyError::Disconnected) => {
self.listener_connections.remove(i);
}
Err(e) => {
warn!(from self, "Unable to send notification via connection {:?} due to {:?}.",
connection, e)
}
Ok(_) => {
number_of_triggered_listeners += 1;
}
} }
}

Ok(number_of_triggered_listeners)
Expand Down
94 changes: 44 additions & 50 deletions iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,17 @@ impl<Service: service::Service> DataSegment<Service> {

fn retrieve_returned_samples(&self) {
for i in 0..self.subscriber_connections.len() {
match self.subscriber_connections.get(i) {
Some(ref connection) => loop {
match connection.sender.reclaim() {
Ok(Some(ptr_dist)) => {
self.release_sample(ptr_dist);
}
Ok(None) => break,
Err(e) => {
warn!(from self, "Unable to reclaim samples from connection {:?} due to {:?}. This may lead to a situation where no more samples will be delivered to this connection.", connection, e)
}
if let Some(ref connection) = self.subscriber_connections.get(i) { loop {
match connection.sender.reclaim() {
Ok(Some(ptr_dist)) => {
self.release_sample(ptr_dist);
}
},
None => (),
}
Ok(None) => break,
Err(e) => {
warn!(from self, "Unable to reclaim samples from connection {:?} due to {:?}. This may lead to a situation where no more samples will be delivered to this connection.", connection, e)
}
}
} }
}
}

Expand Down Expand Up @@ -356,53 +353,50 @@ impl<Service: service::Service> DataSegment<Service> {

let mut number_of_recipients = 0;
for i in 0..self.subscriber_connections.len() {
match self.subscriber_connections.get(i) {
Some(ref connection) => {
match deliver_call(&connection.sender, PointerOffset::new(address_to_chunk)) {
Err(ZeroCopySendError::ReceiveBufferFull)
| Err(ZeroCopySendError::UsedChunkListFull) => {
/* causes no problem
* blocking_send => can never happen
* try_send => we tried and expect that the buffer is full
* */
}
Err(ZeroCopySendError::ConnectionCorrupted) => {
match &self.config.degration_callback {
Some(c) => match c.call(
self.static_config.clone(),
self.port_id,
connection.subscriber_id,
) {
DegrationAction::Ignore => (),
DegrationAction::Warn => {
error!(from self,
"While delivering the sample: {:?} a corrupted connection was detected with subscriber {:?}.",
address_to_chunk, connection.subscriber_id);
}
DegrationAction::Fail => {
fail!(from self, with PublisherSendError::ConnectionCorrupted,
"While delivering the sample: {:?} a corrupted connection was detected with subscriber {:?}.",
address_to_chunk, connection.subscriber_id);
}
},
None => {
if let Some(ref connection) = self.subscriber_connections.get(i) {
match deliver_call(&connection.sender, PointerOffset::new(address_to_chunk)) {
Err(ZeroCopySendError::ReceiveBufferFull)
| Err(ZeroCopySendError::UsedChunkListFull) => {
/* causes no problem
* blocking_send => can never happen
* try_send => we tried and expect that the buffer is full
* */
}
Err(ZeroCopySendError::ConnectionCorrupted) => {
match &self.config.degration_callback {
Some(c) => match c.call(
self.static_config.clone(),
self.port_id,
connection.subscriber_id,
) {
DegrationAction::Ignore => (),
DegrationAction::Warn => {
error!(from self,
"While delivering the sample: {:?} a corrupted connection was detected with subscriber {:?}.",
address_to_chunk, connection.subscriber_id);
}
DegrationAction::Fail => {
fail!(from self, with PublisherSendError::ConnectionCorrupted,
"While delivering the sample: {:?} a corrupted connection was detected with subscriber {:?}.",
address_to_chunk, connection.subscriber_id);
}
},
None => {
error!(from self,
"While delivering the sample: {:?} a corrupted connection was detected with subscriber {:?}.",
address_to_chunk, connection.subscriber_id);
}
}
Ok(overflow) => {
self.borrow_sample(address_to_chunk);
number_of_recipients += 1;
}
Ok(overflow) => {
self.borrow_sample(address_to_chunk);
number_of_recipients += 1;

if let Some(old) = overflow {
self.release_sample(old)
}
if let Some(old) = overflow {
self.release_sample(old)
}
}
}
None => (),
}
}
Ok(number_of_recipients)
Expand Down
22 changes: 8 additions & 14 deletions iceoryx2/src/port/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,10 @@ impl<Service: service::Service, Payload: Debug + ?Sized, UserHeader: Debug>
"Some samples are not being received since not all connections to publishers could be established.");

for id in 0..self.publisher_connections.len() {
match &self.publisher_connections.get(id) {
Some(ref connection) => {
if connection.receiver.has_data() {
return Ok(true);
}
if let Some(ref connection) = &self.publisher_connections.get(id) {
if connection.receiver.has_data() {
return Ok(true);
}
None => (),
}
}

Expand All @@ -368,15 +365,12 @@ impl<Service: service::Service, Payload: Debug + ?Sized, UserHeader: Debug>
}

for id in 0..self.publisher_connections.len() {
match &mut self.publisher_connections.get_mut(id) {
Some(ref mut connection) => {
if let Some((details, absolute_address)) =
self.receive_from_connection(connection)?
{
return Ok(Some((details, absolute_address)));
}
if let Some(ref mut connection) = &mut self.publisher_connections.get_mut(id) {
if let Some((details, absolute_address)) =
self.receive_from_connection(connection)?
{
return Ok(Some((details, absolute_address)));
}
None => (),
}
}

Expand Down

0 comments on commit f64ba6f

Please sign in to comment.