Skip to content

Commit c2fe44d

Browse files
committed
Call xbd_gcoap_req_send() via extern "C" {
1 parent cb2f889 commit c2fe44d

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

examples/xbd-net/src/xbd/gcoap.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ fn gcoap_put_inner(addr: &str, uri: &str, payload: &[u8], fstat_ptr: *mut Future
289289
fn gcoap_req(addr: &str, uri: &str, method: CoapMethod,
290290
payload: Option<&[u8]>, blockwise: bool, blockwise_state_index: Option<usize>,
291291
fstat_ptr: *mut FutureState<GcoapMemoState>) {
292+
293+
extern "C" {
294+
fn xbd_gcoap_req_send(
295+
addr: *const u8, uri: *const u8, method: u8,
296+
payload: *const u8, payload_len: usize,
297+
blockwise: bool, idx: usize,
298+
context: *const c_void, resp_handler: *const c_void);
299+
}
300+
292301
let payload_ptr = payload.map_or(core::ptr::null(), |payload| payload.as_ptr());
293302
let payload_len = payload.map_or(0, |payload| payload.len());
294303

@@ -300,20 +309,14 @@ fn gcoap_req(addr: &str, uri: &str, method: CoapMethod,
300309
uri_cstr.push_str(uri).unwrap();
301310
uri_cstr.push('\0').unwrap();
302311

303-
type Ty = unsafe extern "C" fn(
304-
*const u8, *const u8, u8,
305-
*const u8, usize, bool, usize, *const c_void, *const c_void);
306-
307312
assert_eq!(blockwise, blockwise_state_index.is_some());
308-
unsafe {
309-
(crate::get_xbd_fn!("xbd_gcoap_req_send", Ty))(
310-
addr_cstr.as_ptr(),
311-
uri_cstr.as_ptr(),
312-
method, payload_ptr, payload_len,
313-
blockwise, blockwise_state_index.unwrap_or(0 /* to be ignored */),
314-
fstat_ptr as *const c_void, // context
315-
gcoap_req_resp_handler as *const c_void);
316-
}
313+
unsafe { xbd_gcoap_req_send(
314+
addr_cstr.as_ptr(),
315+
uri_cstr.as_ptr(),
316+
method, payload_ptr, payload_len,
317+
blockwise, blockwise_state_index.unwrap_or(0 /* to be ignored */),
318+
fstat_ptr as *const c_void, // context
319+
gcoap_req_resp_handler as *const c_void); }
317320
}
318321

319322
fn gcoap_req_resp_handler(memo: *const c_void, pdu: *const c_void, remote: *const c_void) {

0 commit comments

Comments
 (0)