Skip to content

feat(wasm32): add Runtime/SessionOpenTask C++ wrappers - #810

Draft
Tobias-Fischer wants to merge 1 commit into
eclipse-zenoh:mainfrom
Tobias-Fischer:wasm32-nonblocking-open
Draft

Tobias-Fischer wants to merge 1 commit into
eclipse-zenoh:mainfrom
Tobias-Fischer:wasm32-nonblocking-open

Conversation

@Tobias-Fischer

Copy link
Copy Markdown

⚠️ This PR was generated by Claude Code and has not yet been human-verified.

zenoh-c's normal synchronous API (z_open() and friends) relies on block_in_place, which panics on wasm32 without atomics (no real threads). eclipse-zenoh/zenoh-c#1338 adds a non-blocking C API for this (zc_runtime_t, zc_open_start/zc_open_poll); this PR adds the corresponding idiomatic C++ wrappers so rmw_zenoh_cpp and other zenoh.hxx consumers can use it without touching the raw C API directly.

Runtime wraps zc_runtime_t (RAII, move-only). SessionOpenTask wraps a pending zc_open_task_t; poll() returns std::nullopt while the session isn't open yet, otherwise the opened Session — reusing the existing interop::as_owned_cpp_ref<Session>() reinterpret-cast idiom already used elsewhere in this codebase to wrap a freshly-populated z_owned_session_t, so no changes to session.hxx were needed.

Verified end-to-end with a real C++ program linked with emcc and run under Node.js (NODERAWSOCKETS) against a native zenohd: non-blocking open succeeds in 4 pumps, and the resulting Session works normally (get_zid(), kept alive and pumped across further ticks) as long as it isn't dropped in the very same pump/tick that opened it — doing that specifically hits a block_in_place panic somewhere in session teardown internals unrelated to this change (zenoh::Session::drop() itself is already wasm32-safe). Root cause not yet isolated, but this doesn't affect the realistic usage pattern of a session kept alive for the program's lifetime.

⚠️ Depends on an unmerged upstream chain, not ready to build against real dependency versions yet: eclipse-zenoh/zenoh#2790–#2799, tokio-rs/mio#2010, tokio-rs/tokio#8489, eclipse-zenoh/zenoh-c#1338.

Still needed for a full rmw_zenoh_cpp port (tracked separately): the actual RMW-side rewrite, replacing rmw_wait_set_data_t's blocking condition_variable.wait() with a cooperative-polling loop driven by Runtime::pump_once().

🤖 Generated with Claude Code

zenoh-c's normal synchronous API (z_open() and friends) relies on
block_in_place, which panics on wasm32 without atomics (no real
threads). zenoh-c's own eclipse-zenoh/zenoh-c#1338 adds a non-blocking
C API for this (zc_runtime_t, zc_open_start/zc_open_poll); this adds
the corresponding idiomatic C++ wrappers so rmw_zenoh_cpp and other
zenoh.hxx consumers can use it without touching the raw C API.

Runtime wraps zc_runtime_t (RAII, move-only). SessionOpenTask wraps a
pending zc_open_task_t; poll() returns std::nullopt while the session
isn't open yet, otherwise the opened Session -- reusing the existing
interop::as_owned_cpp_ref<Session>() reinterpret-cast idiom already
used elsewhere in this codebase to wrap a freshly-populated
z_owned_session_t, no changes to session.hxx needed.

Verified end-to-end with a real C++ program linked with emcc and run
under Node.js (NODERAWSOCKETS) against a native zenohd: non-blocking
open succeeds in 4 pumps, and the resulting Session works normally
(zid queryable, kept alive and pumped across further ticks) as long as
it isn't dropped in the very same pump/tick that opened it -- doing
that specifically hits a block_in_place panic somewhere in session
teardown internals unrelated to this change (zenoh::Session::drop()
itself is already wasm32-safe); root cause not yet isolated, but this
doesn't affect the realistic usage pattern of a session kept alive for
the program's lifetime.

Depends on an unmerged upstream chain, not ready to build against real
dependency versions yet: eclipse-zenoh/zenoh#2790-2799,
tokio-rs/mio#2010, tokio-rs/tokio#8489, eclipse-zenoh/zenoh-c#1338.

Generated by Claude Code; not yet human-verified.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant