Skip to content

Commit

Permalink
Merge pull request #431 from xieyuschen/iox2-430-fix-clippy-error
Browse files Browse the repository at this point in the history
[#430] Fix clippy single match warning in package iceoryx2
  • Loading branch information
elBoberido authored Oct 3, 2024
2 parents 6d25b61 + e6ba9cc commit fe1fc38
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 60 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
9 changes: 4 additions & 5 deletions iceoryx2/src/port/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,19 @@ 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) {
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)
connection, e)
}
Ok(_) => {
number_of_triggered_listeners += 1;
}
},
None => (),
}
}
}

Expand Down
78 changes: 37 additions & 41 deletions iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ 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 {
if let Some(ref connection) = self.subscriber_connections.get(i) {
loop {
match connection.sender.reclaim() {
Ok(Some(ptr_dist)) => {
self.release_sample(ptr_dist);
Expand All @@ -303,8 +303,7 @@ impl<Service: service::Service> DataSegment<Service> {
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)
}
}
},
None => (),
}
}
}
}
Expand Down Expand Up @@ -356,53 +355,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 fe1fc38

Please sign in to comment.