C · Calling

Calling

#include <ucall/types.h>#include <ucall/client.h> 1.0.0-rc.1 · 60202332

ucall_client_call() returns a synchronous acceptance outcome; success guarantees one completion and refusal produces none. Keep the borrowed URL, headers, body, and security-key inputs alive until completion retrieval. ucall_client_take_completed() drives progress and retrieves a batch of records containing the caller cookie, final outcome, and response. Retrieval returns each call’s admission credit. The connection budget must be positive; a zero call budget uses the connection budget times max_pipelined_calls. Retrieved responses belong to the caller until ucall_client_response_free(); client teardown discards unretrieved results. Response accessors take only the response, which stays readable after its client is freed. HTTP calls support connection reuse, pipelining, chunked receive framing, redirects, and request deadlines. A client’s max_pipelined_calls bounds the calls one connection carries at once, and no call is pipelined behind one that is not idempotent or that sends Connection: close. A pipelined connection lost mid-flight retries its unanswered idempotent calls and finishes the rest with ucall_status_connection_closed_k. Calls a server left unread when it announced a close are sent again on a new connection. Host names go through a built-in stub resolver driven by the client’s own engine: /etc/resolv.conf with search and ndots and /etc/hosts on POSIX, the adapters’ settings on Windows, AAAA and A over UDP with TCP on truncation, CNAME chains, and answers cached for their TTL. Connections race the answered addresses as RFC 8305’s Happy Eyeballs does. max_response_bytes caps what a call buffers, failing with ucall_status_overflow_k past it, and the client’s log reports failed dials, refused handshakes and refused redirects.

API

Types

ucall_client_tOpaque client handle.
types.h:156 ↗
typedef struct ucall_client_handle_t * ucall_client_t;

At a high level, a client is responsible for:

  • Establishing connections to one or more servers, reusing encryption keys between requests.
  • Following redirects chains automatically, unless disabled.
  • Driving accepted calls when the application polls for completions.

See also

ucall_received_http_response_tOpaque handle for a single Remote Procedure Call reply on the client side.
types.h:166 ↗
typedef struct ucall_received_http_response_handle_t * ucall_received_http_response_t;
ucall_client_options_tConfiguration parameters for the UCall client.
client.h:20 ↗
struct ucall_client_options_t

Fields

max_concurrent_connectionssize_tRequired positive budget for simultaneously open connections.
max_pipelined_callssize_tCalls one connection may carry before the next call opens or waits for another; zero means one.
connect_timeout_microsecondssize_tTime budget for establishing a connection.
call_timeout_microsecondssize_tTime budget for a full request-response exchange.
noise_private_keyucall_noise_key_t const *Client identity for handshakes.
peer_authorizerucall_peer_authorizer_tVets server static keys.
peer_authorizer_contextvoid *Passed verbatim to peer_authorizer.
logucall_log_tWhere log lines go.
max_concurrent_callssize_tAccepted calls, including unretrieved completions; zero uses the connection budget times max_pipelined_calls.
backenducall_io_backend_tRequested I/O backend; automatic chooses an available native backend.
cpu_classucall_cpu_class_tCeiling on the CPU class: the newest compiled class under it runs, and unknown takes the initialization thread's capabilities.
max_response_bytessize_tLargest response a call buffers, head and body, past which it fails with ucall_status_overflow_k, as max_request_bytes bounds a server's requests.
serverucall_server_tA server whose event loop drives this client, or NULL for a client with its own engine.
event_loopsize_tWhich of server's event loops; ignored without server.

See also

Initialize with ucall_client_init().

ucall_client_call_options_tOptions of one client call: time budget, retries, redirects and security.
client.h:117 ↗
struct ucall_client_call_options_t

Fields

timeout_microsecondssize_tTime budget including queueing and redirects.
max_retriessize_tAdditional connection attempts before sending the request.
max_redirectssize_tRedirect hops followed before failing.
securityucall_security_tTransport security for this call.
noise_private_keyucall_noise_key_t const *The client's identity; needed for KK.
noise_peer_keyucall_noise_key_t const *The server's expected key; needed for IK and KK.
ucall_completed_call_tA final result for one accepted client call.
client.h:193 ↗
struct ucall_completed_call_t

Fields

contextvoid *Cookie supplied when the call was submitted.
outcomeucall_outcome_tFinal network or protocol outcome, independent of the acceptance result.
responseucall_received_http_response_tReceived response, or NULL on failure.

Functions

ucall_client_initInitializes the client state.
client.h:105 ↗
void ucall_client_init(ucall_client_init_t *arguments);

Parameters

clientucall_client_t *Output for the new client.
outcomeucall_outcome_t *Synchronous initialization result.
optionsucall_client_options_t const *Requested configuration.
resolveducall_client_options_t *Optional output for options with every default filled in.

Notes

One owner at a time may submit, poll, or free the client, on any thread.

Statuses

ucall_client_freeFrees the client state.
client.h:114 ↗
void ucall_client_free(ucall_client_t client);

Does nothing for NULL.

Parameters

clientinClient from ucall_client_init(), or NULL.

Notes

Cancels accepted calls and discards unretrieved completions. Retrieved responses remain caller-owned and readable. Do not submit or poll concurrently with teardown.

ucall_client_callSubmits one HTTP exchange without driving network progress.
client.h:190 ↗
void ucall_client_call(ucall_client_call_t *arguments);

Parameters

clientucall_client_tThe client this call operates on.
outcomeucall_outcome_t *Synchronous acceptance result.
urlucall_bytes_view_tFull URL, with an explicit byte length.
verbucall_verb_tHTTP method, like ucall_verb_get_k or ucall_verb_post_k, etc.
headersucall_bytes_view_t const *Every HTTP header line, each as a counted byte view.
headers_countsize_tNumber of strings in the headers array.
bodyucall_bytes_view_tRequest body; an empty view sends no payload.
optionsucall_client_call_options_tPer-request timeouts, retries, redirects, and security.
contextvoid *Caller cookie returned with the final completion.

Notes

  • Success guarantees exactly one record from ucall_client_take_completed(). Keep URL, headers, body, and security-key inputs alive until that completion is retrieved. The argument struct and acceptance outcome may be reused after submission returns. One owner submits and polls this client; calls are not internally synchronized.
  • Host, Content-Length, and User-Agent are generated by the client. Do not supply them in the header array. Redirects obey ucall_client_call_options_t::max_redirects.

Statuses

ucall_client_take_completedDrives client I/O and retrieves a batch of final call results on the calling thread.
client.h:239 ↗
void ucall_client_take_completed(
    ucall_client_take_completed_t *arguments);

Parameters

clientucall_client_tClient whose accepted calls to advance.
outcomeucall_outcome_t *Outcome of polling, independently of the completed calls' outcomes.
callsucall_completed_call_t *Caller-owned completion storage.
capacitysize_tEntries available in calls; zero advances I/O without retrieving completions.
countsize_t *Output for the number of retrieved entries.
timeout_microsecondssize_tMaximum wait for completions; zero performs one bounded nonblocking progress round.

Notes

Retrieving a completion returns its admission credit. Free its response after use. Only one owner may submit or poll this client at a time.

Statuses

ucall_client_response_statusReturns the HTTP status of a received response.
client.h:246 ↗
ucall_http_status_t ucall_client_response_status(
    ucall_received_http_response_t response);

Parameters

responseinResponse from ucall_client_take_completed().

Returns

The peer's status code, or zero for a null response.

ucall_client_response_headerExtracts the named string header from the received response.
client.h:278 ↗
void ucall_client_response_header(
    ucall_client_response_header_t *arguments);

Header name matching is case-insensitive per RFC 7230.

Parameters

responseucall_received_http_response_tThe received response from ucall_client_take_completed(), readable after its client is freed.
outcomeucall_outcome_t *The verb's status, listed on the verb.
nameucall_bytes_view_tThe name of the HTTP header to extract (case-insensitive).
valueucall_bytes_view_t *Output for a borrowed view of the header value.

Notes

Thread-safe across responses, though two threads must not use one response at once.

Statuses

ucall_client_response_fields_countCounts the header field lines of the received response, repeated names included.
client.h:303 ↗
void ucall_client_response_fields_count(
    ucall_client_response_fields_count_t *arguments);

Parameters

responseucall_received_http_response_tThe received response from ucall_client_take_completed(), readable after its client is freed.
outcomeucall_outcome_t *The verb's status, listed on the verb.
countsize_t *Output for the number of header field lines, in arrival order.

Notes

Thread-safe across responses, though two threads must not use one response at once.

Statuses

ucall_client_response_fieldExtracts one header field line of the received response by its arrival order.
client.h:336 ↗
void ucall_client_response_field(
    ucall_client_response_field_t *arguments);

Parameters

responseucall_received_http_response_tThe received response from ucall_client_take_completed(), readable after its client is freed.
outcomeucall_outcome_t *The verb's status, listed on the verb.
indexsize_tWhich field line, below ucall_client_response_fields_count().
nameucall_bytes_view_t *Output for a borrowed view of its name, lowercased as the parser keeps every field name.
valueucall_bytes_view_t *Output for a borrowed view of its value, without surrounding whitespace.

Notes

Thread-safe across responses, though two threads must not use one response at once.

Statuses

ucall_client_response_bodyExtracts the body content from the received response.
client.h:361 ↗
void ucall_client_response_body(
    ucall_client_response_body_t *arguments);

Parameters

responseucall_received_http_response_tThe received response from ucall_client_take_completed(), readable after its client is freed.
outcomeucall_outcome_t *The verb's status, listed on the verb.
bodyucall_bytes_view_t *Output for a borrowed view of the body.

Notes

Thread-safe across responses, though two threads must not use one response at once.

Statuses

ucall_client_response_freeFrees the received response handle.
client.h:370 ↗
void ucall_client_response_free(
    ucall_received_http_response_t response);

Does nothing for NULL.

Parameters

responseinThe received response from ucall_client_take_completed(), or NULL.

Notes

Thread-safe across responses. Two threads must not operate on the same response concurrently.