Repository navigation
feat(codegen/cpp): a typed client for the poll mode - #276
Draft
Ivansete-status wants to merge 6 commits into
Draft
Ivansete-status wants to merge 6 commits into
Ivansete-status wants to merge 6 commits into
Conversation
A -d:ffiPollMode library hands out messages through <lib>_poll and never calls the host back, so each host needs its own pump. Ship the C++ one as headers: it owns no thread, which leaves the host free to choose its own event loop, and a call pumps on the caller until its reply. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A timed-out call's late reply would otherwise leak; ctx is read across threads. Adds a scripted fake-library test and says "poll mode". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A closed context left submit callbacks waiting forever and a poll that reported CLOSED left drain() spinning on a context already gone, so both now mark the context closed and tell every pending callback. A library reply carrying RET_TIMEOUT was mistaken for the host's own deadline and left a stale entry behind; the host now records its deadline explicitly. drain() no longer blocks an event loop behind another thread's call(). The header's message block is now the library's own cMsgDecl output, checked byte for byte, since only names and values were compared before and the docs had drifted. The usage example moves into the header comment: the repo takes no new .md files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
call() and submit() take raw CBOR and the library's export pointers, so a reader should know a typed client is meant to wrap them rather than users calling them directly. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
9 of 13 tasks
A C++ developer should not write the OS-specific wait to serve the queue. runLoop() blocks the calling thread until stop(), for an app with no loop; poll() serves what is waiting and returns, for a loop that calls it each iteration or when fd() is readable. Neither starts a thread, so the developer decides which thread serves; ~Host stops and waits for a running runLoop(). attach() serves a context the library owns (its static context) without destroying it. Handlers run on the serving thread, so Host times each one and reports one that keeps the queue past a limit. The header comment is one pass through what a reader cannot guess. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Under -d:ffiPollMode the generated C++ header declares the poll-shaped exports and a context class over nim_ffi::Host, so a host calls typed methods instead of passing raw CBOR and export pointers to Host::call, and gets typed event listeners matched by name id. Static procs go through a host attached to the library's static context, and the class forwards runLoop(), poll() and stop(). The fixed C++ lives in three templates and the emitter fills in what depends on the library's procs. The callback model's output is byte-identical to before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ivansete-status
force-pushed
the
feat/poll-cpp-client
branch
from
November 21, 2026 01:23
b2ac1d7 to
b85d261
Compare
This was referenced Nov 21, 2026
Ivansete-status
force-pushed
the
feat/poll-host-cpp
branch
2 times, most recently
from
November 23, 2026 12:18
7385022 to
182a388
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #271 (base is
feat/poll-host-cpp; retarget to master once #271 merges). Second of the four PRs (#271, this, #278, #279). Part of #266.Under
-d:ffiPollModethe C++ generator now emits:extern "C"declarations,<Lib>Ctxclass overnim_ffi::Host:create(...), one typed method per proc (encode,Host::call, decode; static procs through a host attached to the library's static context), a typedaddOn<Event>Listenermatched by name id, andrunLoop(),poll(),stop(),fd()andhost()forwarded from the host,nim_ffi_host.hppandnim_ffi.hbeside the header.Methods return errors that name the call (
"echo: ..."), and an event payload that cannot be decoded is reported on stderr. The fixed C++ lives in three templates (poll_exports,poll_context,poll_items); the emitter only fills in what depends on the library's procs.Not here: typed reverse-call handlers (#278) and an example (#279).
Callback mode is unchanged: the shared top of the header and the callback client moved into procs verbatim, and the generated output is byte-identical for a sample library (checked by diff).
Test:
tests/unit/test_cpp_poll_codegen.nimgenerates the header and builds it (ASan/UBSan where available) against a scripted fake library: create, a typed call, a static call that fails before the static context exists and then succeeds, an event ahead of the reply, listener removal,poll()andrunLoop()/stop(). #279 runs it against a real library.🤖 Generated with Claude Code