Skip to content

Commit

Permalink
gcoap.rs: Clean up code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
j-devel committed Jun 26, 2024
1 parent 40df8bc commit cb2f889
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions examples/xbd-net/src/xbd/gcoap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GcoapMemoState>) {
Expand Down

0 comments on commit cb2f889

Please sign in to comment.