curl -s 'https://www.unum.cloud/docs/ucall/cpp/calling.md' | claude -p "How would this fit my code?"
A client_t submits calls without driving the network, and polls to drive them and collect what finished.
It holds up to max_concurrent_connections connections, reusing them across calls, and carries up to max_pipelined_calls calls on each.
submit takes a client_call_t, whose URL, header lines and body the caller keeps until the call completes, and tags it with a void* context.
A call admitted once completes exactly once, and a client already holding its call budget of unretrieved calls refuses more with status_code_t::contended_k. take_completed drives every admitted call and fills the front of the storage the caller passes with finished ones, waiting up to its timeout for the first, and a zero timeout performs one nonblocking round.
It answers a completed_view_t, which hands each completed_t over once by take or by iterating and frees the responses never taken. get, post, put, delete_, patch and call submit one call and wait for it alone, while the library keeps the completions of other calls queued for the next take_completed. client_call_t::options carries the call’s own client_call_options_t: a timeout in place of the client’s, retries, redirect hops, security, and the client and server keys.
Every received response is a response_t, whatever its HTTP status, and only a failed exchange is a failed status.
A response_t owns its received bytes, frees them when destroyed, stays readable after its client_t is destroyed and may move to another thread.
Destroying the client cancels the calls still in flight and discards completions not yet retrieved.
A call whose body_delivery is ucall_body_delivery_streamed_k completes once its head arrived, so a download larger than max_response_bytes is pulled through response_t::body_chunk as it lands, while response_t::body reads empty.
A pull never waits: with nothing decoded yet it answers status_code_t::would_block_k, and an empty take_completed advances the client, moving the next bytes in.
Every streamed response is pulled to its end or destroyed, as its connection carries no other call meanwhile; destroying it early closes that connection and fails the calls pipelined behind it.
API
Types
client_options_tWhat a client may hold open at once, how long it waits, and who it is under Noise; zero fields take their documented defaults, except the connection budget, which is required.
The received response, whatever its HTTP status, or the failed exchange's status.
completed_view_tThe calls one client_t::take_completed finished, in the caller's storage and the order they finished, each handed over once by take or by iterating; the responses never taken are freed with the view.
It owns its handle alone: completions land in storage the caller passes, and a blocking call takes its own completion out of the library, leaving the others queued there.
makeStarts a client, which holds no connection until its first call is polled.
take_completedDrives every admitted call on this thread and fills the front of storage with finished ones, waiting up to timeout for the first; empty storage only advances the network.
Pulls run on the client's thread and never wait: with nothing decoded yet the pull answers status_code_t::would_block_k, and polling the client moves the next bytes in.