Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed May 20, 2022
1 parent 2a80688 commit f733795
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
34 changes: 13 additions & 21 deletions io/zenoh-transport/src/unicast/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,29 +390,21 @@ impl TransportUnicastInner {
pub(crate) async fn close_link(&self, link: &LinkUnicast, reason: u8) -> ZResult<()> {
log::trace!("Closing link {} with peer: {}", link, self.config.pid);

let guard = zread!(self.links);
if let Some(l) = zlinkget!(guard, link) {
let mut pipeline = l.pipeline.clone();
// Drop the guard
drop(guard);

// Schedule the close message for transmission
if let Some(pipeline) = pipeline.take() {
// Close message to be sent on the target link
let peer_id = Some(self.config.manager.pid());
let reason_id = reason;
let link_only = true; // This is should always be true when closing a link
let attachment = None; // No attachment here
let msg = TransportMessage::make_close(peer_id, reason_id, link_only, attachment);

pipeline.push_transport_message(msg, Priority::Background);
}
let mut pipeline = zlinkget!(zread!(self.links), link)
.map(|l| l.pipeline.clone())
.ok_or_else(|| zerror!("Cannot close Link {:?}: not found", link))?;
if let Some(p) = pipeline.take() {
// Close message to be sent on the target link
let peer_id = Some(self.config.manager.pid());
let reason_id = reason;
let link_only = true; // This is should always be true when closing a link
let attachment = None; // No attachment here
let msg = TransportMessage::make_close(peer_id, reason_id, link_only, attachment);

// Remove the link from the channel
self.del_link(link).await?;
p.push_transport_message(msg, Priority::Background);
}

Ok(())
// Remove the link from the channel
self.del_link(link).await
}

pub(crate) async fn close(&self, reason: u8) -> ZResult<()> {
Expand Down
Binary file modified zenoh-dragon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions zenoh/src/net/routing/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Network {
}
Some((
pid,
link_state.whatami.or(Some(WhatAmI::Router)).unwrap(),
link_state.whatami.unwrap_or(WhatAmI::Router),
link_state.locators,
link_state.sn,
link_state.links,
Expand All @@ -313,7 +313,7 @@ impl Network {
match src_link.get_pid(&link_state.psid) {
Some(pid) => Some((
*pid,
link_state.whatami.or(Some(WhatAmI::Router)).unwrap(),
link_state.whatami.unwrap_or(WhatAmI::Router),
link_state.locators,
link_state.sn,
link_state.links,
Expand Down
8 changes: 3 additions & 5 deletions zenoh/src/net/runtime/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,9 @@ impl Runtime {
#[allow(clippy::or_fun_call)]
let local_addr = socket
.local_addr()
.or::<std::io::Error>(Ok(SocketAddr::new(addr, 0).into()))
.unwrap()
.unwrap_or(SocketAddr::new(addr, 0).into())
.as_socket()
.or(Some(SocketAddr::new(addr, 0)))
.unwrap();
.unwrap_or(SocketAddr::new(addr, 0));
log::debug!("UDP port bound to {}", local_addr);
}
Err(err) => {
Expand Down Expand Up @@ -551,7 +549,7 @@ impl Runtime {
if let Some(msg) = zbuf.reader().read_transport_message() {
log::trace!("Received {:?} from {}", msg.body, peer);
if let TransportBody::Hello(hello) = &msg.body {
let whatami = hello.whatami.or(Some(WhatAmI::Router)).unwrap();
let whatami = hello.whatami.unwrap_or(WhatAmI::Router);
if matcher.matches(whatami) {
if let Loop::Break = f(hello.clone()).await {
break;
Expand Down

0 comments on commit f733795

Please sign in to comment.