From cb2f889e6e47a2e2936540235c2b9c991145b129 Mon Sep 17 00:00:00 2001 From: j-devel <38098238+j-devel@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:27:52 +0700 Subject: [PATCH] gcoap.rs: Clean up code blocks --- examples/xbd-net/src/xbd/gcoap.rs | 45 +++++++++++++------------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/examples/xbd-net/src/xbd/gcoap.rs b/examples/xbd-net/src/xbd/gcoap.rs index 36e5837..584b472 100644 --- a/examples/xbd-net/src/xbd/gcoap.rs +++ b/examples/xbd-net/src/xbd/gcoap.rs @@ -235,48 +235,39 @@ impl Future for ReqInner { let fstat_ptr = self.fstat.as_mut_ptr(); match self.method { - COAP_METHOD_GET => { - if self.blockwise { - let idx = self.blockwise_state_index.unwrap(); - - if BlockwiseData::state_is_valid(idx) { - BlockwiseData::set_state_last(Some(idx)); - BlockwiseData::update_state(idx, - self.addr.as_bytes(), - self.uri.as_bytes(), - self.blockwise_hdr.as_deref()); - - gcoap_get_blockwise_inner(&self.addr, &self.uri, idx, fstat_ptr); - } else { // blockwise stream could be already closed - BlockwiseData::set_state_last(None); - - return Poll::Ready(GcoapMemoState::Err) - } - } else { - gcoap_get_inner(&self.addr, &self.uri, fstat_ptr); + COAP_METHOD_GET if self.blockwise => { + let idx = self.blockwise_state_index.unwrap(); + + if BlockwiseData::state_is_valid(idx) { + BlockwiseData::set_state_last(Some(idx)); + BlockwiseData::update_state(idx, + self.addr.as_bytes(), + self.uri.as_bytes(), + self.blockwise_hdr.as_deref()); + + gcoap_get_blockwise_inner(&self.addr, &self.uri, idx, fstat_ptr); + } else { // blockwise stream could be already closed + BlockwiseData::set_state_last(None); + return Poll::Ready(GcoapMemoState::Err) } }, + COAP_METHOD_GET if !self.blockwise => gcoap_get_inner( + &self.addr, &self.uri, fstat_ptr), COAP_METHOD_POST => gcoap_post_inner( &self.addr, &self.uri, self.payload.as_ref().unwrap().as_slice(), fstat_ptr), COAP_METHOD_PUT => gcoap_put_inner( &self.addr, &self.uri, self.payload.as_ref().unwrap().as_slice(), fstat_ptr), - _ => todo!(), + _ => panic!(), } Poll::Pending }, - FutureState::Resolved(_) => { - Poll::Ready(self.fstat.take()) - }, + FutureState::Resolved(_) => Poll::Ready(self.fstat.take()), _ => panic!(), } } } -unsafe impl Send for ReqInner { - // !!!! !!!! -} - // fn gcoap_get_blockwise_inner(addr: &str, uri: &str, blockwise_state_index: usize, fstat_ptr: *mut FutureState) {