diff --git a/examples/xbd-net/src/lib.rs b/examples/xbd-net/src/lib.rs index 29bf0c8..3e7802c 100644 --- a/examples/xbd-net/src/lib.rs +++ b/examples/xbd-net/src/lib.rs @@ -163,9 +163,11 @@ async fn xbd_main() { //panic!("ok"); // !!!! // WIP multiple-static blockwise streams !! - let mut bs = Xbd::async_gcoap_get_blockwise(addr_self, "/const/song.txt"); // FIXME AlreadyInit + let mut bs = Xbd::async_gcoap_get_blockwise(addr_self, "/const/song.txt"); while let Some(req) = bs.next().await { - panic!("{:?}", req); + let out = req.await; + println!("@@ out: {:?}", out); + panic!("!!"); } } } @@ -190,4 +192,4 @@ async fn xbd_main() { let out = Xbd::async_gcoap_get(req_external_native.0, req_external_native.1).await; println!("@@ out: {:?}", out); } -} +} \ No newline at end of file diff --git a/examples/xbd-net/src/xbd/blockwise.rs b/examples/xbd-net/src/xbd/blockwise.rs index 6dc118c..7907803 100644 --- a/examples/xbd-net/src/xbd/blockwise.rs +++ b/examples/xbd-net/src/xbd/blockwise.rs @@ -113,8 +113,10 @@ pub fn add_blockwise_req(req: ReqInner) { pub struct BlockwiseStream(XbdStream); impl BlockwiseStream { - pub fn new() -> Self { - Self(XbdStream::new(&BLOCKWISE_QUEUE, &BLOCKWISE_WAKER)) + pub fn get() -> Self { + XbdStream::get(&BLOCKWISE_QUEUE, &BLOCKWISE_WAKER) + .map_or_else(|| Self(XbdStream::new(&BLOCKWISE_QUEUE, &BLOCKWISE_WAKER)), + |xs| Self(xs)) } } diff --git a/examples/xbd-net/src/xbd/gcoap.rs b/examples/xbd-net/src/xbd/gcoap.rs index 2deede8..f58b62b 100644 --- a/examples/xbd-net/src/xbd/gcoap.rs +++ b/examples/xbd-net/src/xbd/gcoap.rs @@ -123,7 +123,7 @@ impl ReqInner { } pub fn new_blockwise(method: CoapMethod, addr: &str, uri: &str, payload: Option>) -> BlockwiseStream { - let bs = BlockwiseStream::new(); + let bs = BlockwiseStream::get(); Self::add_blockwise(method, addr, uri, payload); bs diff --git a/examples/xbd-net/src/xbd/stream.rs b/examples/xbd-net/src/xbd/stream.rs index b484d68..3ddb83c 100644 --- a/examples/xbd-net/src/xbd/stream.rs +++ b/examples/xbd-net/src/xbd/stream.rs @@ -18,6 +18,14 @@ impl XbdStream { XbdStream { queue, waker } } + pub fn get(queue: &'static OnceCell>, waker: &'static AtomicWaker) -> Option { + if queue.get().is_some() { // already init_once + Some(XbdStream { queue, waker }) + } else { + None + } + } + // must not block/alloc/dealloc pub fn add(queue: &'static OnceCell>, waker: &'static AtomicWaker, item: T) { if let Ok(queue) = queue.try_get() {