Skip to content

Commit

Permalink
remove peer from socketmap on error
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethKnudsen97 committed Oct 27, 2023
1 parent f1a4de6 commit caebe54
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ublox-short-range/src/wifi/udp_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ where
socket: &mut Self::UdpSocket,
remote: SocketAddr,
) -> Result<(), Self::Error> {
let mut peer_handle = crate::command::PeerHandle(0);

Check warning on line 64 in ublox-short-range/src/wifi/udp_stack.rs

View workflow job for this annotation

GitHub Actions / clippy

value assigned to `peer_handle` is never read

warning: value assigned to `peer_handle` is never read --> ublox-short-range/src/wifi/udp_stack.rs:64:17 | 64 | let mut peer_handle = crate::command::PeerHandle(0); | ^^^^^^^^^^^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default

if self.sockets.is_none() {
defmt::error!("[UDP] Connecting socket Error: Missing socket set");
return Err(Error::Illegal);
Expand All @@ -86,10 +88,13 @@ where
.send_internal(&EdmAtCmdWrapper(ConnectPeer { url: &url }), true)
.map_err(|_| Error::Unaddressable)
{
Ok(resp) => self
.socket_map
.insert_peer(resp.peer_handle, *socket)
.map_err(|_| Error::InvalidSocket)?,
Ok(resp) => {
peer_handle = resp.peer_handle;

self.socket_map
.insert_peer(resp.peer_handle, *socket)
.map_err(|_| Error::InvalidSocket)?
}

Err(e) => {
let mut udp = self
Expand All @@ -109,7 +114,14 @@ where
.state()
== UdpState::Closed
{
self.spin().map_err(|_| Error::Illegal)?;
match self.spin() {
Ok(_) => {}
Err(_) => {
defmt::error!("ERROR connection UDP removing peer");
self.socket_map.remove_peer(&peer_handle);
return Err(Error::Illegal);
}
};
}
Ok(())
}
Expand Down

0 comments on commit caebe54

Please sign in to comment.