From 60b0e3df870fe54cc2f693323c1d2306f1054a17 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 19 Oct 2021 15:01:36 +0800 Subject: [PATCH] handle the expected error from the disconnect call When disconnecting from a remote server that was destroyed, we would expect (and get) a ServerNotFound error. --- services/net/src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 52219c1f5..c75aac84d 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -227,9 +227,18 @@ fn xmain() -> ! { let mut cid_to_disconnect: Option = None; loop { let mut msg = xous::receive_message(net_sid).unwrap(); - if let Some(_dc_cid) = cid_to_disconnect.take() { // disconnect previous loop iter's connection after d/c OK response was sent - // CHECK WITH XOBS: maybe these connections are auto-closed when the server is destroyed? - // unsafe{xous::disconnect(dc_cid).expect("couldn't disconnect from dropped UDP object")}; + if let Some(dc_cid) = cid_to_disconnect.take() { // disconnect previous loop iter's connection after d/c OK response was sent + unsafe{ + match xous::disconnect(dc_cid) { + Ok(_) => {}, + Err(xous::Error::ServerNotFound) => { + log::trace!("Disconnect returned the expected error code for a remote that has been destroyed.") + }, + Err(e) => { + log::error!("Attempt to de-allocate CID to destroyed server met with error: {:?}", e); + }, + } + } } match FromPrimitive::from_usize(msg.body.id()) { Some(Opcode::UdpBind) => {