# UCall for C++

> Clients and servers behind one C ABI, with Noise instead of TLS, io_uring to IOCP and server-side batching, from C++

`cmake --build build_release --target ucall_static` 1.0.0-rc.1 · b7577426

## Installation

`#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

Build the static library from a checkout; the C++ headers sit over it and need nothing else:

```sh
cmake -B build_release -D CMAKE_BUILD_TYPE=Release
cmake --build build_release --target ucall_static
```

The C++ interface is header-only over the C one: `cpp/ucall/*.hpp` include only `c/ucall/*.h` and the standard library, and a program links `ucall_static`. In CMake, link `ucall::cpp`, which carries the C headers of `ucall::abi` and the archive `ucall::static`, and which `find_package(ucall)` names once installed, or add the repository as a subdirectory. It needs a C++23 compiler: GCC 15, Clang 22 with libstdc++ 15 or libc++ 22, Xcode 26 or VS 2026. It throws nothing. The library picks its I/O backend and CPU kernels when a server or client starts, so one build adapts to the kernel and CPU it runs on.

### API

#### Functions

##### `version_name`

The linked library's version, a release-candidate suffix included.

[types.hpp:337 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L337)

```cpp
std::string_view version_name() noexcept;
```

## Quickstart

1.0.0-rc.1 · b7577426

A server answers on one or more interfaces, and a client calls it; neither starts a thread.

```cpp
#include <thread>

#include <ucall/ucall.hpp>

namespace uc = unum::ucall;

void greet(uc::request_t request) noexcept {
    auto [name, name_status] = request.path_parameter("name");
    if (name_status.failed()) return;
    ucall_reply_part_t const parts[] {uc::bytes_part("Hello, "), uc::bytes_part(name)};
    ucall_bytes_view_t const headers[] {uc::bytes_view("content-type: text/plain")};
    uc::deferred<> sent; // final on return, as the parts are bytes alone
    [[maybe_unused]] uc::status_t const replied =
        std::move(request).reply_parts(ucall_http_status_ok_k, headers, parts, sent);
}

int main() {
    uc::interface_t const interfaces[] {{.address = "127.0.0.1:0"}};
    auto [server, server_status] = uc::server_t::make(interfaces);
    if (server_status.failed()) return 1;
    uc::status_t const routed = server.get<greet>("/hello/{name}");
    if (routed.failed()) return 1;
    auto [address, address_status] = server.address(0);

    auto [client, client_status] = uc::client_t::make({.max_concurrent_connections = 1});
    std::thread polling([&server] { [[maybe_unused]] uc::status_t const polled = server.take_calls(0); });
    char url[128];
    std::snprintf(url, sizeof url, "http://%.*s/hello/world", int(address.size()), address.data());
    auto [response, response_status] = client.get(url);
    server.stop();
    polling.join();
    auto [body, body_status] = response.body();
    return response_status.failed() || body_status.failed() || body != "Hello, world";
}
```

The polling thread runs the handler, the client blocks in `get` until its response arrives, and `stop` releases the polling thread so it can be joined. Every fallible verb answers a `status_t` or an `expected<T>`, unpacked as `auto [value, status]`.

## Serving

`#include <ucall/server.hpp>``#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

`server_t::make` takes the interfaces to answer on, as an array whose size the compiler knows, and optionally `server_options_t`: the backend, a CPU class ceiling that caps the picked class rather than demanding one the machine lacks, a `log_t` sink and a StatsD endpoint. It fails rather than substituting when the backend is unavailable or the CPU does not run the class. An `interface_t` is an address, optionally pinned to a Linux device, with its own security and admission limits, so one server answers plaintext on loopback and Noise on the wire at once. `server_t::memory_domain` reports the NUMA node the kernel ties an interface’s device to, or -1, so the application inits and polls from threads there; UCall places nothing by it. It admits 1024 connections by default, reads one request per connection at a time unless `max_pipelined_requests` allows more, and replies still leave in request order. Once an interface holds its whole `max_concurrent_connections` budget, a new peer evicts the idle keep-alive connection that progressed least recently. A connection that has not yet carried a request is never idle in this sense, so it is never evicted: its peer may have sent that request already. `max_request_bytes` caps a request’s head and buffered body, answering 413 past it, and `reply_directories` names the directories path replies resolve beneath. `listen_descriptor` accepts on a listener another owner opened instead of binding an address, and never closes it. Port zero binds a free port, which `server_t::address` reports.

```cpp
void list_files(uc::request_t request) noexcept {
    auto [user, user_status] = request.path_parameter("user");
    auto [path, path_status] = request.path_parameter("path");
    ucall_reply_part_t const parts[] {uc::bytes_part(user), uc::bytes_part(":"), uc::bytes_part(path)};
    uc::deferred<> sent;
    [[maybe_unused]] uc::status_t const replied =
        std::move(request).reply_parts(ucall_http_status_ok_k, {}, parts, sent);
}

void not_served(uc::request_t request) noexcept {
    [[maybe_unused]] uc::status_t const replied =
        std::move(request).reply_error(ucall_http_status_not_implemented_k, "This method is not served");
}

auto log_line = [](ucall_log_level_t level, std::string_view line) noexcept {
    std::fprintf(stderr, "%d %.*s\n", int(level), int(line.size()), line.data());
};
uc::interface_t const interfaces[] {
    {.address = "0.0.0.0:8545", .event_loops = 4, .max_concurrent_connections = 16'384, .max_pipelined_requests = 16},
    {.address = "127.0.0.1:8546", .max_concurrent_connections = 4},
};
uc::server_options_t const options {
    .log = {log_line, ucall_log_format_human_k, ucall_log_level_warning_k},
    .metrics_address = "127.0.0.1:8125",
    .metrics_prefix = "myapp",
    .cpu_class_ceiling = ucall_cpu_class_serial_k,
};
auto [server, server_status] = uc::server_t::make(interfaces, options);
std::printf("%zu event loops on %.*s\n", server.event_loops(), int(uc::io_backend_name(server.backend()).size()),
            uc::io_backend_name(server.backend()).data());

uc::status_t const listed = server.get<list_files>("/users/{user}/files/{*path}");
uc::status_t const fallback = server.route<not_served>("/anything", ucall_verb_any_k);
```

Routes register before any loop is polled, with `route` taking any verb and `get`, `post`, `put`, `delete_` and `patch` naming one; `delete_` carries an underscore, as `delete` is a keyword. A handler is a `noexcept` function taking `request_t` by value, named as a template argument, as in `server.get<greet>(path)`; a member function named the same way with its object, as in `server.post<&service_t::echo>(path, service)`; or a callable with state, such as a lambda with captures, passed as an argument. The server refers to a member’s object or a callable, which the caller keeps until the server is destroyed, and keeps no record of a route; log sinks and peer authorizers are callables the caller keeps alike. Every polling loop may run a route at once, so a callable, a log sink and a peer authorizer are called through a const call operator, and a member’s object must be safe to call from several threads, like an internally synchronized store. Templates capture `{name}` segments and a greedy `{*name}` tail, literal segments match before captures, and registering one template and verb twice fails with `status_code_t::already_exists_k`. Routing is exact: an empty segment is a segment, so `/users` and `/users/` are different paths. A path no route matches answers 404, one whose routes take other verbs answers 405 with an `allow` header, a GET route also serves HEAD, and `OPTIONS` answers 204 with the same `allow` list.

Log lines reach the handler on whichever thread produced them, and StatsD datagrams carry each loop’s counters and sampled request latencies, every second unless `metrics_interval` says otherwise. `server_t::event_loop_statistics` copies one loop’s counters, from any thread while the loop runs; divided by `requests`, they price one call.

### API

#### Types

##### `local_batch_endpoint_t`

One local batch endpoint, whose event loops each fire their own batches, so nothing drains it; valid until its server is freed.

[server.hpp:544 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L544)

```cpp
class local_batch_endpoint_t
```

##### `interface_t`

One address a server answers on, with the security and admission limits of the connections arriving there.

[server.hpp:570 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L570)

```cpp
struct interface_t
```

##### Fields

| `address` | `std::string_view` | The listening address in "host:port" form; port zero picks a free one. |
| - | - | - |
| `listen_descriptor` | `std::intptr_t const *` | A listening stream socket another owner opened, accepted on instead of [`address`](#address). |
| `device_name` | `std::string_view` | A physical device to pin the interface to, like "eth0", on Linux only. |
| `security` | `ucall_security_t` | Encryption for connections accepted here. |
| `noise_private_key` | `ucall_noise_key_t const *` | The server identity for handshakes, needed by every Noise mode. |
| `noise_peer_key` | `ucall_noise_key_t const *` | The one initiator's static public key Noise KK admits. |
| `noise_pre_shared_key` | `ucall_noise_key_t const *` | A secret every client also holds, mixed first into every handshake; refused on plaintext. |
| `key_exchange` | `ucall_key_exchange_t` | The key exchange of Noise handshakes, which clients must match. |
| `peer_authorizer` | `peer_authorizer_t` | Vets each client's authenticated key, needed by Noise XX. |
| `event_loops` | `std::size_t` | Event loops accepting here; zero means one, or a named device's receive queues. |
| `max_concurrent_connections` | `std::size_t` | Connections open at once across this interface's loops. |
| `max_pipelined_requests` | `std::size_t` | Requests one connection may have in flight; zero means one. |
| `max_request_bytes` | `std::size_t` | The largest request head and buffered body; zero takes the largest receive buffer. |
| `reply_directories` | `std::span<ucall_bytes_view_t const>` | Directories that path parts of replies resolve beneath, by position. |
| `send_policy` | `ucall_send_policy_t` | How replies of a page or more leave: copied to peers on this host, pinned for the rest. |

##### `server_options_t`

What a server runs on and reports through, beside its interfaces.

[server.hpp:639 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L639)

```cpp
struct server_options_t
```

##### Fields

| `log` | `log_t` | Where log lines go; empty keeps the server silent. |
| - | - | - |
| `metrics_address` | `std::string_view` | The StatsD endpoint in "host:port" form; empty sends nothing. |
| `metrics_sample_rate` | `float` | The fraction of finished requests whose latency is reported; zero means all. |
| `metrics_prefix` | `std::string_view` | The metric name prefix; empty means "ucall". |
| `metrics_tags` | `std::span<ucall_bytes_view_t const>` | Tags on every metric, each "key:value". |
| `metrics_interval` | `std::chrono::microseconds` | The time between one event loop's datagrams; zero means one second. |
| `backend` | `ucall_io_backend_t` | The requested I/O backend, failing rather than substituting when it is unavailable. |
| `cpu_class_ceiling` | `ucall_cpu_class_t` | A ceiling on the CPU class; unknown sets none. |

##### `log_t`

The log sink of a server or a client: a handler the caller keeps for its lifetime, the line format, and the least severe level formatted; empty logs nothing.

[types.hpp:448 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L448)

```cpp
class log_t
```

##### Class `pooled_batch_endpoint_t`

One pooled batch endpoint, whose one queue gathers every event loop's requests and is drained by one thread at a time; valid until its server is freed.4

[server.hpp:497 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L497)

```cpp
class pooled_batch_endpoint_t
```

###### `pooled_batch_endpoint_t`

[server.hpp:502 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L502)

```cpp
pooled_batch_endpoint_t() noexcept=default;
```

```cpp
pooled_batch_endpoint_t(
    ucall_server_t server,
    ucall_http_batch_endpoint_t endpoint) noexcept;
```

###### `take_batch`

Runs the handler on this thread if a batch is due, waiting up to `timeout` for one; zero performs one nonblocking round.

[server.hpp:508 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L508)

```cpp
status_t take_batch(std::chrono::microseconds timeout) const noexcept;
```

###### `take_batches`

Runs the handler on this thread for every due batch until the server stops.

[server.hpp:519 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L519)

```cpp
status_t take_batches() const noexcept;
```

###### `statistics`

A snapshot of the endpoint's counters, readable from any thread while it is polled.

[server.hpp:528 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L528)

```cpp
expected<batch_endpoint_statistics_t> statistics() const noexcept;
```

##### Class `server_t`

An HTTP server over one or more interfaces, polled by application threads.17

[server.hpp:674 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L674)

```cpp
class server_t
```

Register every route before any loop is polled, then poll each event loop from one thread at a time. Destroying it frees the server, which the bound clients must not outlive. A route keeps nothing here: its handler is a template argument, and a member's object or a callable is the context the library hands back.

###### `make`

Starts a server answering on `interfaces`, whose callbacks it calls until it is freed.

[server.hpp:753 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L753)

```cpp
template <std::size_t count_>
expected<server_t> make(
    interface_t const (&) interfaces,
    server_options_t const & options = {}) noexcept;
```

###### `event_loops`

Event loops the server runs, each polled by one thread at a time.

[server.hpp:784 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L784)

```cpp
std::size_t event_loops() const noexcept;
```

###### `backend`

The I/O backend the server resolved to.

[server.hpp:792 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L792)

```cpp
ucall_io_backend_t backend() const noexcept;
```

###### `cpu_class_ceiling`

The CPU class the server resolved to under its ceiling.

[server.hpp:795 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L795)

```cpp
ucall_cpu_class_t cpu_class_ceiling() const noexcept;
```

###### `address`

The numeric address interface `index` listens on, with the port it bound.

[server.hpp:798 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L798)

```cpp
expected<std::string_view> address(std::size_t index) const noexcept;
```

###### `memory_domain`

The NUMA node the kernel ties interface `index's` device to, or -1; init and poll from threads there.

[server.hpp:807 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L807)

```cpp
expected<std::int32_t> memory_domain(std::size_t index) const noexcept;
```

###### `route`

Routes requests matching [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) and [`verb`](https://www.unum.cloud/docs/ucall/cpp/requests.md#verb) to the plain function `function_`, which runs on the polling thread.

[server.hpp:823 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L823)

```cpp
template <request_function_t function_>
status_t route(
    std::string_view path,
    ucall_verb_t verb,
    ucall_body_delivery_t delivery = ucall_body_delivery_buffered_k) noexcept;
```

```cpp
template <auto member_, typename object_type_>
requires a_request_handling_member<member_, object_type_>
status_t route(
    std::string_view path,
    ucall_verb_t verb,
    object_type_ & object,
    ucall_body_delivery_t delivery = ucall_body_delivery_buffered_k) noexcept;
```

Routes like the function overload to the member function `member_` of `object`, which the caller keeps until the server is freed.

```cpp
template <a_request_handler handler_type_>
status_t route(
    std::string_view path,
    ucall_verb_t verb,
    handler_type_ & handler,
    ucall_body_delivery_t delivery = ucall_body_delivery_buffered_k) noexcept;
```

Routes like the function overload to a `handler` with state, which the caller keeps until the server is freed.

Templates capture `{name}` segments and a greedy `{*name}` tail; literal segments match before captures. A streamed `delivery` runs the handler once the headers arrive, the body still to be pulled through `request_t::body_chunk`.

###### `get`

Routes GET requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to the function or member `handler_`, the member's object following the path.

[server.hpp:849 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L849)

```cpp
template <auto handler_, typename... object_types_>
status_t get(std::string_view path, object_types_ &... object) noexcept;
```

```cpp
template <a_request_handler handler_type_>
status_t get(std::string_view path, handler_type_ & handler) noexcept;
```

Routes GET requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to a `handler` the caller keeps.

###### `post`

Routes POST requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to the function or member `handler_`.

[server.hpp:861 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L861)

```cpp
template <auto handler_, typename... object_types_>
status_t post(
    std::string_view path,
    object_types_ &... object) noexcept;
```

```cpp
template <a_request_handler handler_type_>
status_t post(std::string_view path, handler_type_ & handler) noexcept;
```

Routes POST requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to a `handler` the caller keeps.

###### `put`

Routes PUT requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to the function or member `handler_`.

[server.hpp:873 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L873)

```cpp
template <auto handler_, typename... object_types_>
status_t put(std::string_view path, object_types_ &... object) noexcept;
```

```cpp
template <a_request_handler handler_type_>
status_t put(std::string_view path, handler_type_ & handler) noexcept;
```

Routes PUT requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to a `handler` the caller keeps.

###### `patch`

Routes PATCH requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to the function or member `handler_`.

[server.hpp:898 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L898)

```cpp
template <auto handler_, typename... object_types_>
status_t patch(
    std::string_view path,
    object_types_ &... object) noexcept;
```

```cpp
template <a_request_handler handler_type_>
status_t patch(std::string_view path, handler_type_ & handler) noexcept;
```

Routes PATCH requests on [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) to a `handler` the caller keeps.

###### `pooled_batch`

Collects requests matching [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) and [`verb`](https://www.unum.cloud/docs/ucall/cpp/requests.md#verb) from every event loop into one queue, which the returned endpoint drains into the plain function `function_` on its polling thread.

[server.hpp:911 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L911)

```cpp
template <batch_function_t function_>
expected<pooled_batch_endpoint_t> pooled_batch(
    std::string_view path,
    ucall_verb_t verb,
    batching_t const & batching) noexcept;
```

```cpp
template <auto member_, typename object_type_>
requires a_batch_handling_member<member_, object_type_>
expected<pooled_batch_endpoint_t> pooled_batch(
    std::string_view path,
    ucall_verb_t verb,
    batching_t const & batching,
    object_type_ & object) noexcept;
```

Batches like the function overload into the member function `member_` of `object`, which the caller keeps until the server is freed.

```cpp
template <a_batch_handler handler_type_>
expected<pooled_batch_endpoint_t> pooled_batch(
    std::string_view path,
    ucall_verb_t verb,
    batching_t const & batching,
    handler_type_ & handler) noexcept;
```

Batches like the function overload into a `handler` with state, which the caller keeps until the server is freed.

###### `local_batch`

Batches requests matching [`path`](https://www.unum.cloud/docs/ucall/cpp/requests.md#path) and [`verb`](https://www.unum.cloud/docs/ucall/cpp/requests.md#verb) per event loop into the plain function `function_`, which each loop runs on its own requests inside [`take_call`](#take_call) or [`take_calls`](#take_calls), where it may reply; it must not take calls itself.

[server.hpp:943 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L943)

```cpp
template <batch_function_t function_>
expected<local_batch_endpoint_t> local_batch(
    std::string_view path,
    ucall_verb_t verb,
    batching_t const & batching) noexcept;
```

```cpp
template <auto member_, typename object_type_>
requires a_batch_handling_member<member_, object_type_>
expected<local_batch_endpoint_t> local_batch(
    std::string_view path,
    ucall_verb_t verb,
    batching_t const & batching,
    object_type_ & object) noexcept;
```

Batches locally like the function overload into the member function `member_` of `object`, which the caller keeps until the server is freed.

```cpp
template <typename handler_type_>
requires a_batch_handler<handler_type_ const>
expected<local_batch_endpoint_t> local_batch(
    std::string_view path,
    ucall_verb_t verb,
    batching_t const & batching,
    handler_type_ & handler) noexcept;
```

Batches locally like the function overload into a `handler` the caller keeps until the server is freed, called through a const call operator, as every polling loop may run it at the same time.

Every polling loop may run it at once, so the object must be safe to call from several threads.

###### `take_call`

Advances one event loop, running the handlers of the requests it completes on this thread, and waits up to `timeout`; [`status_code_t::connection_closed_k`](https://www.unum.cloud/docs/ucall/cpp/errors.md#connection_closed_k) means the loop retired after [`stop`](#stop).

[server.hpp:974 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L974)

```cpp
status_t take_call(
    std::size_t event_loop,
    std::chrono::microseconds timeout) const noexcept;
```

###### `take_calls`

Drives one event loop on this thread until [`stop`](#stop) or an I/O failure.

[server.hpp:985 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L985)

```cpp
status_t take_calls(std::size_t event_loop) const noexcept;
```

###### `stop`

Requests shutdown from any thread, handlers included: the first call drains, answering the requests already held, and a second one cuts the replies still in flight.

[server.hpp:995 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L995)

```cpp
void stop() const noexcept;
```

###### `event_loop_statistics`

A snapshot of one event loop's counters, readable from any thread while it is polled.

[server.hpp:998 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L998)

```cpp
expected<event_loop_statistics_t> event_loop_statistics(
    std::size_t event_loop) const noexcept;
```

#### Functions

##### `io_backend_name`

The stable name of an I/O backend, such as "linux-uring618".

[types.hpp:313 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L313)

```cpp
std::string_view io_backend_name(ucall_io_backend_t backend) noexcept;
```

##### `io_backend_from_name`

Reads an I/O backend back from its stable name, "automatic" included.

[types.hpp:316 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L316)

```cpp
expected<ucall_io_backend_t> io_backend_from_name(
    std::string_view name) noexcept;
```

## Requests

`#include <ucall/types.hpp>``#include <ucall/server.hpp>` 1.0.0-rc.1 · b7577426

A handler receives each `request_t` by value, owning it. Its reads view the received bytes: `verb`, `path`, `query_string`, `path_parameter`, `query`, `header` and `body`, with `peer` naming the interface it arrived on, the client’s authenticated Noise key and its socket address. Every read that can fail answers an `expected`, so a missing header answers `status_code_t::not_found_k` and a body read on a streamed route `status_code_t::invalid_argument_k`, while the counts answer plain numbers. The path and query values stay percent-encoded as sent, which `uc::decode_percent` decodes, header names match case-insensitively, and the body arrives whole, decoded from chunked framing if it was sent that way. `fields_count` and `field` read every header field in arrival order, names lowercased and values trimmed, as a proxy forwards a head. `path_segments_count` and `path_segment` read the path component by component, and `parts_count` and `part` read a `multipart/form-data` body as `request_part_t` s.

```cpp
void order(uc::request_t request) noexcept {
    auto [token, token_status] = request.header("authorization");
    if (token_status.failed()) {
        [[maybe_unused]] uc::status_t const refused =
            std::move(request).reply_error(ucall_http_status_unauthorized_k, "sign in first");
        return;
    }
    auto [order_id, order_status] = request.path_parameter("order");
    ucall_bytes_view_t const headers[] {uc::bytes_view("content-type: text/plain"),
                                        uc::bytes_view("cache-control: no-store")};
    ucall_reply_part_t const parts[] {uc::bytes_part(order_id), uc::bytes_part(" by "), uc::bytes_part(token)};
    uc::deferred<> sent;
    [[maybe_unused]] uc::status_t const replied =
        std::move(request).reply_parts(ucall_http_status_created_k, headers, parts, sent);
}
```

`reply`, `reply_error`, `reply_parts` and `reply_stream` take the request, spelled `std::move(request).reply(...)`, and Content-Length, Date and Server are generated. A reply copies the bytes it sends before it returns, so a body made of the request’s bytes needs no copy of its own. A request moves to any thread, so a handler may hand it to a worker and return, and the worker replies whenever it is done. A request destroyed without a reply answers 500. The library clears the request’s handle once a reply took it, a closed connection included, which reports `status_code_t::connection_closed_k`; a reply it refused keeps the handle, and destroying the request then answers 500.

### API

#### Types

##### `request_part_t`

One part of a `multipart/form-data` request body, viewing the received bytes.

[server.hpp:37 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L37)

```cpp
struct request_part_t
```

##### Fields

| `name` | `std::string_view` | The name its `Content-Disposition` gives. |
| - | - | - |
| `content_type` | `std::string_view` | Its `Content-Type`, empty when absent. |
| `data` | `std::string_view` | Its payload, undecoded. |

##### `peer_t`

Who sent a request: the interface it arrived on, the client's authenticated static key, zeroed in plaintext, and its socket address.

[server.hpp:51 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L51)

```cpp
struct peer_t
```

##### Fields

| `network_interface_index` | `std::size_t` | The position of the interface among those the server answers on. |
| - | - | - |
| `static_key` | `ucall_noise_key_t` | The client's authenticated Noise static key, zeroed on plaintext interfaces. |
| `address` | `ucall_peer_address_t` | The client's socket address as accepted. |

##### `string_view >`

The bytes a call wrote into a counted view, read back as text once the call is final.

[types.hpp:290 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L290)

```cpp
template <>
struct string_view >
```

##### Fields

| `value` | `ucall_bytes_view_t` | The view the call writes in place. |
| - | - | - |

##### `field_t`

One header field line, its name lowercased and its value trimmed.

[types.hpp:354 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L354)

```cpp
struct field_t
```

##### Fields

| `name` | `std::string_view` | The field name, lowercased as the parser keeps it. |
| - | - | - |
| `value` | `std::string_view` | The field value, without surrounding whitespace. |

##### Class `deferred`

A submitted call: its outcome and its outputs, owned until the call is final, while the receiver, inputs, arena and handlers it was handed stay allocated and unchanged until then.7

[types.hpp:116 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L116)

```cpp
template <typename value_type_ = void>
class deferred
```

It never moves, as the library writes into it, and its one owner polls [`status`](#status), blocks in [`wait`](#wait) or awaits [`wait`](#wait) on its own loop; destruction waits, so nothing the call writes into goes away under it.

###### `answer_type`

What [`wait`](#wait) answers: what the blocking call would have.

[types.hpp:122 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L122)

```cpp
using answer_type = std::conditional_t<std::is_void_v<value_type_>, status_t, expected<value_type_>>;
```

###### `deferred`

An empty slot, final from the start, which [`resubmit`](#resubmit) fills.

[types.hpp:125 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L125)

```cpp
deferred() noexcept=default;
```

```cpp
template <typename submit_type_>
requires std::invocable<submit_type_ const&, ucall_outcome_t*, outputs<value_type_>*>
deferred(submit_type_ const & submit) noexcept;
```

Runs [`submit`](https://www.unum.cloud/docs/ucall/cpp/calling.md#submit) with this call's outcome and outputs, where the library reports.

```cpp
deferred(status_t status) noexcept;
```

A call refused before it crossed, final from the start.

```cpp
deferred(deferred const &)=delete;
```

###### `resubmit`

Waits only while the slot's previous call still runs, then runs [`submit`](https://www.unum.cloud/docs/ucall/cpp/calling.md#submit) in its place.

[types.hpp:137 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L137)

```cpp
template <typename submit_type_>
requires std::invocable<submit_type_ const&, ucall_outcome_t*, outputs<value_type_>*>
void resubmit(submit_type_ const & submit) noexcept;
```

###### `operator=`

[types.hpp:148 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L148)

```cpp
deferred & operator=(deferred const &)=delete;
```

###### `~deferred`

[types.hpp:149 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L149)

```cpp
~deferred() noexcept;
```

###### `status`

[`status_code_t::deferred_k`](https://www.unum.cloud/docs/ucall/cpp/errors.md#deferred_k) until the call is final, then its final status, polled without blocking.

[types.hpp:153 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L153)

```cpp
status_code_t status() noexcept;
```

###### `wait`

Blocks until the call is final and answers what a blocking call would have.

[types.hpp:156 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L156)

```cpp
answer_type wait() noexcept;
```

```cpp
template <a_scheduler scheduler_type_>
awaiter<value_type_, scheduler_type_> wait(
    scheduler_type_ & loop) noexcept;
```

Awaits the call on `loop`, which polls its status until it is final.

##### Class `request_t`

A received request, owned by one thread at a time, answered at most once.22

[server.hpp:141 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L141)

```cpp
class request_t
```

Reads view the received bytes until the reply. A reply takes the request, as in `std::move(request)`.reply(...), and a request destroyed without one answers 500. A reply the library refused leaves the request retained, answering 500 once destroyed.

###### `request_t`

[server.hpp:174 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L174)

```cpp
request_t() noexcept=default;
```

```cpp
request_t(
    ucall_server_t server,
    ucall_received_http_request_t request) noexcept;
```

```cpp
request_t(request_t && other) noexcept;
```

```cpp
request_t(request_t const &)=delete;
```

###### `operator=`

[server.hpp:178 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L178)

```cpp
request_t & operator=(request_t && other) noexcept;
```

```cpp
request_t & operator=(request_t const &)=delete;
```

###### `~request_t`

[server.hpp:186 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L186)

```cpp
~request_t() noexcept;
```

###### `verb`

The HTTP method, which tells apart the requests of an endpoint taking any verb.

[server.hpp:200 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L200)

```cpp
ucall_verb_t verb() const noexcept;
```

###### `path`

The path as sent, still percent-encoded, without the query.

[server.hpp:203 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L203)

```cpp
expected<std::string_view> path() const noexcept;
```

###### `query_string`

The query after the first '?

[server.hpp:208 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L208)

```cpp
expected<std::string_view> query_string() const noexcept;
```

', still percent-encoded, or empty without one.

###### `body`

The body, decoded from chunked framing if it arrived that way; a streamed endpoint refuses it, as [`body_chunk`](https://www.unum.cloud/docs/ucall/cpp/calling.md#body_chunk) pulls its body.

[server.hpp:214 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L214)

```cpp
expected<std::string_view> body() const noexcept;
```

###### `path_parameter`

The value the endpoint's template captured under `name`, case-sensitive.

[server.hpp:219 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L219)

```cpp
expected<std::string_view> path_parameter(
    std::string_view name) const noexcept;
```

###### `query`

The value of query parameter `name`, case-sensitive and still percent-encoded.

[server.hpp:224 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L224)

```cpp
expected<std::string_view> query(std::string_view name) const noexcept;
```

###### `header`

The value of header `name`, matched case-insensitively.

[server.hpp:229 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L229)

```cpp
expected<std::string_view> header(std::string_view name) const noexcept;
```

###### `fields_count`

Header field lines, repeated names apart.

[server.hpp:234 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L234)

```cpp
std::size_t fields_count() const noexcept;
```

###### `field`

Header field line `index` in arrival order.

[server.hpp:237 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L237)

```cpp
expected<field_t> field(std::size_t index) const noexcept;
```

###### `path_segments_count`

Path components, as sent and still percent-encoded.

[server.hpp:253 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L253)

```cpp
std::size_t path_segments_count() const noexcept;
```

###### `path_segment`

Path component `index`, counting from zero.

[server.hpp:258 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L258)

```cpp
expected<std::string_view> path_segment(
    std::size_t index) const noexcept;
```

###### `parts_count`

Parts of a `multipart/form-data` body, zero for any other body.

[server.hpp:273 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L273)

```cpp
std::size_t parts_count() const noexcept;
```

###### `part`

Part `index` of a `multipart/form-data` body, its payload undecoded.

[server.hpp:276 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L276)

```cpp
expected<request_part_t> part(std::size_t index) const noexcept;
```

###### `peer`

The interface the request arrived on, the client's key and its address, readable after its connection closed.

[server.hpp:294 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L294)

```cpp
expected<peer_t> peer() const noexcept;
```

###### `body_chunk`

Pulls the body bytes decoded since the last pull into `into`, empty once the body ended and valid until the next pull or the reply; answers a refusal, or success while the pull runs.

[server.hpp:319 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L319)

```cpp
status_t body_chunk(deferred<std::string_view> & into) noexcept;
```

On a streamed endpoint the pull is final once the bytes arrive, which the polling thread delivers; a pull from the polling thread itself finding nothing answers [`status_code_t::would_block_k`](https://www.unum.cloud/docs/ucall/cpp/errors.md#would_block_k) instead. On a buffered one the first pull is the whole body. The slot waits for its previous call first, if that still runs.

###### `reply`

Replies with `http_status`, full header lines like "content-type: text/plain", and [`body`](https://www.unum.cloud/docs/ucall/cpp/calling.md#body), generating the length, date and server lines.

[server.hpp:333 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L333)

```cpp
status_t reply(
    ucall_http_status_t http_status,
    std::span<ucall_bytes_view_t const> headers,
    std::string_view body) &&noexcept;
```

###### `reply_error`

Replies with an error `http_status`, 400 or above, and a plain-text `message`.

[server.hpp:348 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L348)

```cpp
status_t reply_error(
    ucall_http_status_t http_status,
    std::string_view message) &&noexcept;
```

###### `reply_parts`

Replies with `http_status`, header lines and `parts` concatenated into the body, its length measured from the files.

[server.hpp:369 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L369)

```cpp
status_t reply_parts(
    ucall_http_status_t http_status,
    std::span<ucall_bytes_view_t const> headers,
    std::span<ucall_reply_part_t const> parts,
    deferred<> & into) &&noexcept;
```

Final on return for bytes alone; with a file or path part the caller's slot `into` stays deferred until every part is sent, which the polling thread does, so await it there or wait elsewhere. Answers a refusal, or success while the parts send. A part failing before the head left replaces the reply with 404, 416 or 500, reported as a status. The slot waits for its previous call first, if that still runs.

###### `reply_stream`

Sends the status line and header lines and opens a body appended part by part: chunked, or of the length a `Content-Length` line declares; a closed connection ends the reply here.

[server.hpp:388 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L388)

```cpp
expected<reply_stream_t> reply_stream(
    ucall_http_status_t http_status,
    std::span<ucall_bytes_view_t const> headers) &&noexcept;
```

#### Functions

##### `bytes_part`

A reply part of bytes in memory, copied before the reply returns.

[server.hpp:64 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L64)

```cpp
ucall_reply_part_t bytes_part(std::string_view bytes) noexcept;
```

##### `bytes_view`

Views `text` as the counted bytes every verb reads, without a copy.

[types.hpp:279 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L279)

```cpp
ucall_bytes_view_t bytes_view(std::string_view text) noexcept;
```

##### `decode_percent`

Decodes the percent escapes of `encoded` into `decoded`, which may alias it, and a '+' as a space in a query, answering the decoded prefix of `decoded`.

[types.hpp:341 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L341)

```cpp
expected<std::string_view> decode_percent(
    std::string_view encoded,
    std::span<char> decoded,
    ucall_percent_mode_t mode) noexcept;
```

#### Constants

##### `is_deferred`

Whether `answer_type_` is a call the caller holds rather than a final answer.

[types.hpp:197 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L197)

```cpp
bool is_deferred;
```

## Files and Streams

`#include <ucall/server.hpp>` 1.0.0-rc.1 · b7577426

Handlers run on the polling thread, so a reply or a pull that finishes later runs in a `deferred` slot the caller keeps, which the polling thread finishes as it keeps polling. Await it on the polling thread through a scheduler, or wait on it from another thread; waiting on the polling thread itself never ends. A verb taking a slot answers a refusal at once, or success while the call runs, and the slot reports the final status. A slot is reused for the next call, waiting first only if its previous call still runs, so a server keeps a ring of slots rather than one per request.

| Verb | Returns | Final when |
| - | - | - |
| `reply_parts(status, headers, parts, into)` | `status_t` | every part is sent |
| `reply_stream(status, headers)` | `expected<reply_stream_t>` | `end()` answers a `deferred<>` |
| `body_chunk(into)` | `status_t` | the next bytes arrived |

A scheduler is any type with `post(void (*poll)(void*) noexcept, void* state)`, which runs `poll(state)` later on its own loop and stores those two words, so awaiting allocates nothing in the binding.

#### Serving a File

Reply with a file beneath a served directory, which the event loop opens and sends, while a coroutine awaits the send:

```cpp
task_t send_video(uc::request_t request, loop_t& loop) {
    auto [name, name_status] = request.path_parameter("name");
    ucall_reply_part_t const parts[] {uc::path_part({.directory_index = 0, .relative_path = uc::bytes_view(name)})};
    uc::deferred<> sent;
    if (std::move(request).reply_parts(ucall_http_status_ok_k, {}, parts, sent).failed()) co_return;
    uc::status_t const sent_status = co_await sent.wait(loop); // or: sent.wait()
}

ucall_bytes_view_t const directories[] {uc::bytes_view("/srv/videos")};
uc::interface_t const interfaces[] {{.address = "0.0.0.0:8080", .reply_directories = directories}};
auto [server, server_status] = uc::server_t::make(interfaces);
auto serve = [&loop](uc::request_t request) noexcept { send_video(std::move(request), loop); };
uc::status_t const routed = server.get("/videos/{name}", serve); // the caller keeps `serve` until the server is destroyed
for (;;) {
    uc::status_t const polled = server.take_call(0, std::chrono::milliseconds(1));
    if (polled == uc::status_code_t::connection_closed_k) break;
    loop.run();
}
```

`reply_parts` concatenates `bytes_part`, `path_part` and `file_part` parts into one body whose Content-Length is measured from the files. A path part resolves beneath the interface’s `reply_directories`, refusing absolute paths, `..` and links leading out, and a file part names the caller’s unbuffered descriptor until the reply is final, while bytes and paths are copied before the call returns. A missing, unreadable or too short file replaces the reply with 404, 416 or 500 before its head leaves, and the awaited status reports the cause. `deferred::status` polls, `deferred::wait()` blocks, `co_await deferred.wait(loop)` re-polls through the loop between other tasks, and a `deferred` waits as it is destroyed, so the coroutine frame, the stack or the ring holding it must outlive the call.

#### Streaming a Reply

Send a reply of unknown length row by row, as a chunked stream:

```cpp
uc::status_t send_rows(uc::request_t request, std::span<std::string_view const> rows) noexcept {
    ucall_bytes_view_t const headers[] {uc::bytes_view("content-type: text/csv")};
    auto [stream, stream_status] = std::move(request).reply_stream(ucall_http_status_ok_k, headers);
    if (stream_status.failed()) return stream_status;
    for (std::string_view row : rows) {
        ucall_reply_part_t const parts[] {uc::bytes_part(row)};
        if (uc::status_t const appended = stream.append(parts); appended.failed()) return appended;
    }
    return std::move(stream).end().wait();
}
```

The stream is chunked unless a Content-Length header declares the length, `append` refuses with `status_code_t::would_block_k`, queueing nothing, while the peer lags behind, and destroying an unended stream ends it.

#### Streaming an Upload

Take a large upload chunk by chunk as it arrives, rather than buffered whole, here only counting its bytes:

```cpp
task_t store(uc::request_t request, loop_t& loop) {
    std::size_t received_bytes = 0;
    uc::deferred<std::string_view> pulled;
    for (;;) {
        if (request.body_chunk(pulled).failed()) break;
        auto [chunk, chunk_status] = co_await pulled.wait(loop); // or: pulled.wait()
        if (chunk_status.failed() || chunk.empty()) break;
        received_bytes += chunk.size();
    }
    std::array<char, 24> total {};
    int const length = std::snprintf(total.data(), total.size(), "%zu", received_bytes);
    ucall_reply_part_t const parts[] {uc::bytes_part({total.data(), std::size_t(length)})};
    uc::deferred<> sent;
    if (std::move(request).reply_parts(ucall_http_status_ok_k, {}, parts, sent).failed()) co_return;
    uc::status_t const replied = co_await sent.wait(loop);
}
```

A route registered with `ucall_body_delivery_streamed_k` runs its handler once the headers arrive, and each `body_chunk` takes the bytes decoded since the last pull, valid until the next one. A pull from another thread blocks in `wait()` until the bytes arrive; on the polling thread a pull with nothing decoded answers `status_code_t::would_block_k` instead, as nothing arrives while it runs.

### API

#### Types

##### `reply_stream_t`

A reply whose head left and whose body is appended part by part until `end`; destroying it ends it and waits for its file parts to send.

[server.hpp:87 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L87)

```cpp
class reply_stream_t
```

#### Functions

##### `memory_part`

A reply part of bytes the caller keeps unchanged until the reply is final, sent in place.

[server.hpp:69 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L69)

```cpp
ucall_reply_part_t memory_part(std::string_view bytes) noexcept;
```

##### `file_part`

A reply part of a range of the caller's unbuffered descriptor, open until the reply is final.

[server.hpp:74 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L74)

```cpp
ucall_reply_part_t file_part(ucall_file_range_t range) noexcept;
```

##### `path_part`

A reply part of a range of a file beneath one of the interface's reply directories.

[server.hpp:79 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L79)

```cpp
ucall_reply_part_t path_part(ucall_path_range_t range) noexcept;
```

## Batches

`#include <ucall/server.hpp>` 1.0.0-rc.1 · b7577426

A pooled batch endpoint gathers matching requests from every event loop into one queue and hands them to its handler in batches, which suits work that is cheaper per request in bulk, like GPU inference.

```cpp
void infer(uc::batch_t batch) noexcept {
    for (uc::request_t request : batch) {
        auto [body, body_status] = request.body();
        std::array<char, 24> score {};
        int const length = std::snprintf(score.data(), score.size(), "%zu", body.size());
        [[maybe_unused]] uc::status_t const replied =
            std::move(request).reply(ucall_http_status_ok_k, {}, {score.data(), std::size_t(length)});
    }
}

uc::interface_t const interfaces[] {{.address = "127.0.0.1:0", .max_pipelined_requests = 8}};
auto [server, server_status] = uc::server_t::make(interfaces);
uc::batching_t const batching {.min_batch_size = 16, .max_batch_size = 64, .max_latency = std::chrono::milliseconds(2)};
auto [endpoint, endpoint_status] = server.pooled_batch<infer>("/infer", ucall_verb_post_k, batching);
std::thread polling([&server] { [[maybe_unused]] uc::status_t const polled = server.take_calls(0); });
std::thread batching_thread([&endpoint] { [[maybe_unused]] uc::status_t const taken = endpoint.take_batches(); });
```

`batching_t` dispatches as soon as `min_batch_size` requests wait, never more than `max_batch_size` at once, and a smaller batch once its oldest request waited `max_latency`; zero fields mean 1, 32 and 10 milliseconds. The handler runs on the thread polling the endpoint through `take_batch` or `take_batches`, never on an event loop, so a slow batch never stalls the network. A `batch_t` holds its requests in arrival order: `take(index)` hands one over, and iterating it hands over each in turn, once, answering 500 for one passed without being taken. A request never taken stays unanswered until the server is destroyed, so take every one; a taken request answers 500 if it is destroyed unreplied. The queue holds as many requests as the interfaces admit at once, connections times pipelined requests, and refuses more with 503. `pooled_batch_endpoint_t::statistics` counts batches and requests, and whether each was dispatched on reaching the maximum size, the minimum size, or the latency. `local_batch` takes the same handlers and `batching_t`, but each event loop fires its own batches inside `take_call` or `take_calls`, so no thread drains them and the handler may reply there; its `local_batch_endpoint_t` offers only `statistics`.

### API

#### Types

##### `batch_t`

The requests one batch callback received, each taken once by `take` or by iterating, which hands them over in arrival order.

[server.hpp:407 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L407)

```cpp
class batch_t
```

A request never taken stays unanswered until the server itself is freed, so take every one.

##### `batching_t`

When a batch endpoint dispatches; zero fields take 1, 32 and 10 milliseconds.

[server.hpp:483 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/server.hpp#L483)

```cpp
struct batching_t
```

##### Fields

| `min_batch_size` | `std::size_t` | Requests that dispatch a batch at once. |
| - | - | - |
| `max_batch_size` | `std::size_t` | Requests one batch holds at most. |
| `max_latency` | `std::chrono::microseconds` | How long the oldest request of a smaller batch waits before it dispatches anyway. |

## Calling

`#include <ucall/client.hpp>``#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

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.

```cpp
auto [client, client_status] = uc::client_t::make({.max_concurrent_connections = 4, .max_pipelined_calls = 16});
std::array<std::uint64_t, 64> contexts {};
std::array<char, 64> bodies {};
for (std::size_t index = 0; index != contexts.size(); ++index) {
    contexts[index] = index, bodies[index] = char(index);
    uc::client_call_t const call {.verb = ucall_verb_post_k, .url = "http://127.0.0.1:8545/infer",
                                  .body = {&bodies[index], 1}};
    uc::status_t const submitted = client.submit(call, &contexts[index]);
}
std::array<ucall_completed_call_t, 16> storage {};
for (std::size_t remaining = contexts.size(); remaining != 0;) {
    auto [finished, finished_status] = client.take_completed(storage, std::chrono::seconds(1));
    for (uc::completed_t done : finished) {
        auto [response, response_status] = std::move(done.response);
        std::printf("call %llu answered %u\n", *static_cast<unsigned long long*>(done.context),
                    response_status.failed() ? 0u : unsigned(response.status_code()));
    }
    remaining -= finished.size();
}

auto [health, health_status] = client.get("http://127.0.0.1:8545/health");
auto [cache_control, cache_control_status] = health.header("cache-control");
```

`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.

#### Streamed Response Bodies

Download a body larger than the client buffers by pulling it chunk by chunk as it lands:

```cpp
uc::client_call_t const call {.url = "http://127.0.0.1:8545/dataset.bin",
                              .options = {.body_delivery = ucall_body_delivery_streamed_k}};
auto [response, response_status] = client.call(call);
std::size_t received_bytes = 0;
for (;;) {
    auto [chunk, chunk_status] = response.body_chunk();
    if (chunk_status == uc::status_code_t::would_block_k) {
        auto [advanced, advanced_status] = client.take_completed({}, std::chrono::milliseconds(1));
        continue;
    }
    if (chunk_status.failed() || chunk.empty()) break;
    received_bytes += chunk.size();
}
```

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_t`

What 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.

[client.hpp:27 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L27)

```cpp
struct client_options_t
```

##### Fields

| `max_concurrent_connections` | `std::size_t` | Connections open at once; zero is refused. |
| - | - | - |
| `max_pipelined_calls` | `std::size_t` | Calls one connection may carry at once; zero means one. |
| `connect_timeout` | `std::chrono::microseconds` | Time budget for establishing a connection; zero means 5 seconds. |
| `call_timeout` | `std::chrono::microseconds` | Time budget for a full exchange, queueing and redirects included; zero means 30 seconds. |
| `noise_private_key` | `ucall_noise_key_t const *` | The client identity for Noise handshakes. |
| `peer_authorizer` | `peer_authorizer_t` | Vets each server's authenticated key, needed by Noise XX calls. |
| `log` | `log_t` | Where log lines go; empty keeps the client silent. |
| `max_concurrent_calls` | `std::size_t` | Calls admitted at once, unretrieved completions included; zero means connections times pipelined calls. |
| `backend` | `ucall_io_backend_t` | The requested I/O backend. |
| `cpu_class_ceiling` | `ucall_cpu_class_t` | A ceiling on the CPU class; unknown sets none. |
| `max_response_bytes` | `std::size_t` | The largest response a call buffers; zero takes the largest receive buffer. |
| `server` | `server_t const *` | A server whose event loop drives this client, polled on that loop's thread only. |
| `event_loop` | `std::size_t` | Which of `server's` event loops. |

##### `client_call_options_t`

One call's time budget, retries, redirects, security and body delivery; zero fields take their defaults.

[client.hpp:72 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L72)

```cpp
struct client_call_options_t
```

##### Fields

| `timeout` | `std::chrono::microseconds` | Time budget including queueing and redirects; zero takes the client's. |
| - | - | - |
| `max_retries` | `std::size_t` | Additional connection attempts; zero means 3. |
| `max_redirects` | `std::size_t` | Redirect hops followed; zero means 5. |
| `security` | `ucall_security_t` | Transport security for this call. |
| `noise_private_key` | `ucall_noise_key_t const *` | The client's identity, needed by Noise KK. |
| `noise_peer_key` | `ucall_noise_key_t const *` | The server's expected key, needed by Noise IK and KK. |
| `noise_pre_shared_key` | `ucall_noise_key_t const *` | The secret the server's interface also holds, mixed first into the handshake; refused on plaintext. |
| `key_exchange` | `ucall_key_exchange_t` | The key exchange of the handshake, which the server must match. |
| `body_delivery` | `ucall_body_delivery_t` | Whether the call completes once the body is buffered, or once the head arrived. |

##### `client_call_t`

One call to submit, whose URL, header lines and body the caller keeps until it completes.

[client.hpp:104 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L104)

```cpp
struct client_call_t
```

##### Fields

| `verb` | `ucall_verb_t` | The HTTP method. |
| - | - | - |
| `url` | `std::string_view` | The full URL, with an `http` or `http+noise` scheme. |
| `headers` | `std::span<ucall_bytes_view_t const>` | Full header lines; the host, length and user agent lines are generated. |
| `body` | `std::string_view` | The request body; empty sends none. |
| `options` | `client_call_options_t` | The call's own budget, security and body delivery. |

##### `completed_t`

One finished call: the context it was submitted with, and its response or why none arrived.

[client.hpp:204 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L204)

```cpp
struct completed_t
```

##### Fields

| `context` | `void *` | The context passed to `client_t::submit`. |
| - | - | - |
| `response` | `expected<response_t>` | The received response, whatever its HTTP status, or the failed exchange's status. |

##### `completed_view_t`

The 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.

[client.hpp:230 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L230)

```cpp
class completed_view_t
```

##### `outputs`

Where a call writes what `value_type_` is made of.

[types.hpp:85 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L85)

```cpp
template <typename value_type_>
struct outputs
```

##### Fields

| `value` | `value_type_` | The answer, which the call writes in place. |
| - | - | - |

##### `outputs< void >`

A call that outputs nothing but its status.

[types.hpp:95 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L95)

```cpp
template <>
struct outputs< void >
```

##### Fields

| `value` | `void` | The answer, which the call writes in place. |
| - | - | - |

##### `awaiter`

A [`deferred`](https://www.unum.cloud/docs/ucall/cpp/requests.md#deferred) being awaited, living in the awaiting coroutine's frame: each poll reads the status word, and one not yet final posts itself again.

[types.hpp:174 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L174)

```cpp
template <typename value_type_,
          a_scheduler scheduler_type_>
class awaiter
```

##### `answer_value`

What a final `answer_type_` carries beside its status, `void` for a bare `status_t`.

[types.hpp:203 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L203)

```cpp
template <typename answer_type_>
struct answer_value
```

##### Class `client_t`

An HTTP client, made, submitted to, polled and destroyed by one owner at a time.8

[client.hpp:287 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L287)

```cpp
class client_t
```

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.

###### `make`

Starts a client, which holds no connection until its first call is polled.

[client.hpp:292 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L292)

```cpp
expected<client_t> make(client_options_t const & options) noexcept;
```

###### `submit`

Admits [`call`](#call) without driving the network; its one completion carries `context`.

[client.hpp:322 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L322)

```cpp
status_t submit(client_call_t const & call, void *context) noexcept;
```

A full client refuses with [`status_code_t::contended_k`](https://www.unum.cloud/docs/ucall/cpp/errors.md#contended_k) until completions are taken.

###### `take_completed`

Drives 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.

[client.hpp:349 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L349)

```cpp
expected<completed_view_t> take_completed(
    std::span<ucall_completed_call_t> storage,
    std::chrono::microseconds timeout) noexcept;
```

###### `call`

Submits [`call`](#call) and polls until it finishes, leaving the completions of other calls queued for [`take_completed`](#take_completed).

[client.hpp:367 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L367)

```cpp
expected<response_t> call(client_call_t const & call) noexcept;
```

The response arrives whatever its HTTP status.

###### `get`

Fetches `url` and polls until the response arrives.

[client.hpp:383 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L383)

```cpp
expected<response_t> get(std::string_view url) noexcept;
```

###### `post`

Posts [`body`](#body) to `url` and polls until the response arrives.

[client.hpp:386 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L386)

```cpp
expected<response_t> post(
    std::string_view url,
    std::string_view body) noexcept;
```

###### `put`

Puts [`body`](#body) at `url` and polls until the response arrives.

[client.hpp:391 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L391)

```cpp
expected<response_t> put(
    std::string_view url,
    std::string_view body) noexcept;
```

###### `patch`

Patches `url` with [`body`](#body) and polls until the response arrives.

[client.hpp:402 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L402)

```cpp
expected<response_t> patch(
    std::string_view url,
    std::string_view body) noexcept;
```

##### Class `response_t`

A received HTTP response, whatever its status, freed on destruction and readable after its client is gone.7

[client.hpp:124 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L124)

```cpp
class response_t
```

###### `response_t`

[client.hpp:129 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L129)

```cpp
response_t() noexcept=default;
```

```cpp
response_t(
    ucall_client_t client,
    ucall_received_http_response_t response) noexcept;
```

###### `status_code`

The status code the server sent.

[client.hpp:137 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L137)

```cpp
ucall_http_status_t status_code() const noexcept;
```

###### `body`

The body, decoded from chunked framing if it arrived that way; a streamed call refuses it, as [`body_chunk`](#body_chunk) pulls its body.

[client.hpp:141 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L141)

```cpp
expected<std::string_view> body() const noexcept;
```

###### `header`

The value of header `name`, matched case-insensitively.

[client.hpp:153 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L153)

```cpp
expected<std::string_view> header(std::string_view name) const noexcept;
```

###### `fields_count`

Header field lines, repeated names apart.

[client.hpp:167 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L167)

```cpp
std::size_t fields_count() const noexcept;
```

###### `field`

Header field line `index` in arrival order.

[client.hpp:170 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L170)

```cpp
expected<field_t> field(std::size_t index) const noexcept;
```

###### `body_chunk`

Pulls the body bytes of a streamed call decoded since the last pull, empty once the body ended, valid until the next pull.

[client.hpp:191 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/client.hpp#L191)

```cpp
expected<std::string_view> body_chunk() noexcept;
```

Pulls run on the client's thread and never wait: with nothing decoded yet the pull answers [`status_code_t::would_block_k`](https://www.unum.cloud/docs/ucall/cpp/errors.md#would_block_k), and polling the client moves the next bytes in.

## Noise Keys

`#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

Interfaces and calls can run over the Noise protocol instead of plain TCP, authenticating both sides by 32-byte Curve25519 static keys.

```cpp
auto [server_keys, server_keys_status] = uc::noise_key_generate();
auto [client_keys, client_keys_status] = uc::noise_key_generate();

auto admit_client = [&client_keys](ucall_noise_key_t const& key) noexcept {
    return uc::noise_keys_equal(key, client_keys.public_key);
};
uc::interface_t const interfaces[] {{.address = "0.0.0.0:8546",
                                     .security = ucall_security_noise_xx_k,
                                     .noise_private_key = &server_keys.private_key,
                                     .peer_authorizer = admit_client}};
auto [server, server_status] = uc::server_t::make(interfaces);

auto admit_server = [&server_keys](ucall_noise_key_t const& key) noexcept {
    return uc::noise_keys_equal(key, server_keys.public_key);
};
auto [client, client_status] = uc::client_t::make(
    {.max_concurrent_connections = 1, .noise_private_key = &client_keys.private_key, .peer_authorizer = admit_server});
```

`noise_key_generate` draws from the operating system’s entropy and fails with `status_code_t::io_k` when it is refused. `noise_key_derive` recovers the public half of a stored private key, which peers compare in their authorizers. Under Noise XX both sides learn each other’s key during the handshake, so both need an authorizer; Noise IK has the client name the server’s key in advance through `client_call_options_t::noise_peer_key`. Noise KK has both sides know each other in advance: the interface admits the one key `interface_t::noise_peer_key` names, and the call presents its own key or the client’s. Both sides may also hold a 32-byte `noise_pre_shared_key`, and must match their `key_exchange`, which defaults to the post-quantum `ucall_key_exchange_x25519_mlkem768_k`. An `http+noise://` URL implies Noise XX, and a handler reads the client’s authenticated key through `request_t::peer`.

### API

#### Types

##### `noise_keypair_t`

A static Curve25519 keypair, the private half kept secret.

[types.hpp:368 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L368)

```cpp
struct noise_keypair_t
```

##### Fields

| `private_key` | `ucall_noise_key_t` | The secret scalar a server interface or a client presents. |
| - | - | - |
| `public_key` | `ucall_noise_key_t` | The public key peers see during the handshake and compare in their authorizers. |

##### `peer_authorizer_t`

A peer authorizer the caller keeps for the server's or the client's lifetime; empty admits nobody under Noise XX, which needs one.

[types.hpp:425 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L425)

```cpp
class peer_authorizer_t
```

#### Functions

##### `noise_key_generate`

Draws a fresh keypair from the operating system's entropy.

[types.hpp:378 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L378)

```cpp
expected<noise_keypair_t> noise_key_generate() noexcept;
```

##### `noise_key_derive`

Derives the public half of a stored `private_key`, answering both halves.

[types.hpp:390 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L390)

```cpp
expected<noise_keypair_t> noise_key_derive(
    ucall_noise_key_t const & private_key) noexcept;
```

##### `noise_keys_equal`

Whether two keys hold the same bytes, as an authorizer compares a peer with the one expected.

[types.hpp:403 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L403)

```cpp
bool noise_keys_equal(
    ucall_noise_key_t const & first,
    ucall_noise_key_t const & second) noexcept;
```

## Errors

`#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

Every fallible verb answers a `status_t`, or an `expected<T>`, a plain pair of a value and its `status_t` unpacked as `auto [value, status]`, whose value is default-constructed on failure. A `status_t` carries a `status_code_t` and an optional static `note` beside it, so nothing allocates on the failure path, and `status == status_code_t::timeout_k` compares the code. Recovery branches on the code, while the note names the broken step or resource for logs, falling back to the status name. A mistake the binding catches before calling the library, like asking for an interface the server lacks, reports the status the library would have used.

```cpp
auto [client, client_status] = uc::client_t::make({.max_concurrent_connections = 1});
auto [response, status] = client.get("http://127.0.0.1:1/");
if (status == uc::status_code_t::connection_failed_k) fmt::println(stderr, "nobody listens: {}", status.note);
```

A submitted call that fails completes with a failed `completed_t::response`: `connection_failed_k`, `connection_closed_k`, `timeout_k`, `handshake_failed_k` or `peer_rejected_k`. HTTP error statuses are ordinary responses. `status_name`, `io_backend_name` and `cpu_class_name` spell stable names, like “linux-uring618” and “intel-icelake”, and their `_from_name` twins parse them back, failing with `status_code_t::invalid_argument_k` on a name no value has. `version_name()` spells the linked library’s version, candidate suffix included, and `decode_percent` decodes a path or a query value, which requests hold still percent-encoded.

### API

#### Types

##### `status_code_t`

What went wrong, with one enumerator per status the library reports.

[types.hpp:34 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L34)

```cpp
enum status_code_t
```

##### Values

| `success_k` | `ucall_status_success_k` | |
| - | - | - |
| `deferred_k` | `ucall_status_deferred_k` | |
| `out_of_memory_k` | `ucall_status_out_of_memory_k` | |
| `io_k` | `ucall_status_io_k` | |
| `malformed_k` | `ucall_status_malformed_k` | |
| `internal_k` | `ucall_status_internal_k` | |
| `overflow_k` | `ucall_status_overflow_k` | |
| `uninitialized_k` | `ucall_status_uninitialized_k` | |
| `contended_k` | `ucall_status_contended_k` | |
| `unsupported_k` | `ucall_status_unsupported_k` | |
| `invalid_argument_k` | `ucall_status_invalid_argument_k` | |
| `not_found_k` | `ucall_status_not_found_k` | |
| `already_exists_k` | `ucall_status_already_exists_k` | |
| `connection_failed_k` | `ucall_status_connection_failed_k` | |
| `connection_closed_k` | `ucall_status_connection_closed_k` | |
| `timeout_k` | `ucall_status_timeout_k` | |
| `handshake_failed_k` | `ucall_status_handshake_failed_k` | |
| `peer_rejected_k` | `ucall_status_peer_rejected_k` | |
| `would_block_k` | `ucall_status_would_block_k` | |

##### `status_t`

Why a call failed: a code recovery branches on, and an optional static note naming the broken invariant, step or resource, for logs and regression analysis.

[types.hpp:60 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L60)

```cpp
struct status_t
```

##### Fields

| `code` | `status_code_t` | |
| - | - | - |
| `note` | `char const *` | |

##### `expected`

A call's value beside its status, bound natively as `auto [value, status]`.

[types.hpp:78 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L78)

```cpp
template <typename value_type_>
struct expected
```

##### Fields

| `value` | `value_type_` | |
| - | - | - |
| `status` | `status_t` | |

#### Functions

##### `status_name`

The stable lowercase spelling of `code`, such as "connection-failed".

[types.hpp:299 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L299)

```cpp
std::string_view status_name(status_code_t code) noexcept;
```

##### `status_from_name`

Reads a status back from the spelling [`status_name`](#status_name) gives it.

[types.hpp:304 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L304)

```cpp
expected<ucall_status_t> status_from_name(
    std::string_view name) noexcept;
```

## Threads and Polling

`#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

The interface starts no threads and needs no runtime: every callback runs on a thread the application gave to a polling call.

- A route handler runs on the thread inside `take_call` or `take_calls` for the event loop that received the request.
- A `pooled_batch` handler runs on the thread inside `take_batch` or `take_batches` for its endpoint, never on an event loop, while a `local_batch` handler runs inside `take_call` or `take_calls` for the loop whose requests it holds.
- A server’s peer authorizer runs on the polling thread completing the handshake, and a client’s on the client’s own thread inside `take_completed` or a blocking call.
- A deferred reply or pull finishes as its event loop polls, so its awaiter re-polls through the caller’s scheduler on that same thread.

Each event loop and each batch endpoint has one polling owner at a time. `take_calls` and `take_batches` run until `server_t::stop`, while `take_call` and `take_batch` return after one round, waiting up to their timeout, so a loop of them interleaves polling with other work, such as a scheduler’s posted polls. `server_t::stop` works from any thread, handlers included, and wakes every polling thread. The first stop drains, answering every request already held before its connection closes, and a second one cuts the replies still in flight. A client bound to a server through `client_options_t::server` advances only as that loop polls, so it is used on that loop’s thread, and its blocking calls would wait forever there. Every thread that polls, replies or reads must run on a CPU supporting the CPU class the server or client resolved at start, so `ucall_cpu_class_serial_k` is the safe choice on machines mixing CPU generations.

### API

#### Functions

##### `cpu_class_name`

The stable name of a CPU kernel class, such as "intel-icelake".

[types.hpp:325 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L325)

```cpp
std::string_view cpu_class_name(ucall_cpu_class_t cpu_class) noexcept;
```

##### `cpu_class_from_name`

Reads a CPU kernel class back from its stable name, "unknown" included.

[types.hpp:328 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L328)

```cpp
expected<ucall_cpu_class_t> cpu_class_from_name(
    std::string_view name) noexcept;
```

## Design

`#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

The interface is a thin layer over UCall’s native library, and every rule below follows from that.

- **Verbs share one name across languages.** `take_call`, `take_calls`, `take_batch`, `take_batches`, `submit` and `take_completed` name the same calls in C++, Go, Python and Rust.
- **Blocking stays simple, deferring stays symmetric.** A reply that is final on return answers a `status_t`, and one that may finish later answers a `deferred` that `wait` s, is awaited through `co_await call.wait(loop)`, or waits as it is destroyed, as Rust’s `Deferred` does when dropped.
- **Ownership is a type, not a flag.** A reply takes its `request_t`, a destroyed request answers 500, a `response_t` frees itself, and a `deferred` never moves, so the stack or the coroutine frame holding it outlives the call.
- **Handlers stay the caller’s, never boxed.** A function or a member is a template argument and an object or a callable with state stays the caller’s until the server or client is destroyed, so registration copies no closure, and every handler is `noexcept`, as no fault can unwind through the library.
- **Polling allocates nothing.** Blocking verbs keep their outcome on the stack, a deferred call keeps it inside itself, and an awaiter posts two words, a function and its own address, into the caller’s scheduler, as Rust’s waker does. A server and a client hold their handles alone: the library hands each callback its server, and a blocking call takes its own completion out of the library’s queue.
- **No life of its own.** The interface starts no threads, keeps no global state and needs no runtime, so it drops into any threading model.

| Path | Rust | C++ |
| - | - | - |
| Blocking verb | 0 | 0 |
| Each handler call | 0 | 0 |
| Deferred reply or pull | 0 | 0, the `deferred` lives in the caller |
| Await | 0 | 0 in the binding |
| Route registration | 1 `Box` | 0 |
| Client start | call tables | 0 |

### API

#### Types

##### `owner`

Owns one handle of `handle_type_`, which `free_` releases, moving it and never copying it.

[types.hpp:240 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L240)

```cpp
template <typename handle_type_,
          void(*)(handle_type_) free_>
class owner
```
