DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3#ifndef DETERMINISTICESPASYNCWEBSERVER_DET_CLIENT_H
4#define DETERMINISTICESPASYNCWEBSERVER_DET_CLIENT_H
5
6/**
7 * @file client.h
8 * @brief Layer 4 outbound TCP client transport - the client-side peer of the
9 * (server) transport in tcp.cpp.
10 *
11 * A small fixed pool of outbound connections so the application's clients
12 * (services/http_client, services/mqtt, services/ws_client) no longer each own a
13 * private raw-lwIP TCP stack at L7. As with the server transport, every raw
14 * `tcp_*()` call is marshaled into `tcpip_thread` via `tcpip_api_call()`, so the
15 * main-loop/worker task never races the stack. All storage is static (no heap).
16 *
17 * The receive ring carries **wire bytes**: for a plaintext connection those are
18 * the application bytes; for a TLS connection they are ciphertext and the caller
19 * layers the shared client-TLS session (`det_tls_csess_*`) on top, pointing its
20 * BIO at det_client_send() / det_client_read().
21 *
22 * The core is non-blocking (read/available/send), so it suits both a polling
23 * client loop (MQTT, WebSocket) and a blocking request (HTTP) that drives its own
24 * deadline. Only det_client_open() blocks, on DNS + connect.
25 */
26
27#include "ServerConfig.h"
28#include <stddef.h>
29#include <stdint.h>
30
31/**
32 * @brief Resolve @p host (dotted-quad fast path, else DNS) and connect to
33 * @p host : @p port, blocking up to @p timeout_ms.
34 * @return A client id in [0, DETWS_CLIENT_CONNS) on success, or < 0 on failure
35 * (pool full, DNS failure, connect timeout/refused).
36 */
37int det_client_open(const char *host, uint16_t port, uint32_t timeout_ms);
38
39/** @brief True once the TCP handshake has completed for @p cid. */
40bool det_client_connected(int cid);
41
42/** @brief True once the peer closed (FIN) or the connection errored. */
43bool det_client_is_closed(int cid);
44
45/** @brief Queue @p len wire bytes for transmission (marshaled tcp_write + output). */
46bool det_client_send(int cid, const void *data, size_t len);
47
48/** @brief Wire bytes currently buffered and ready to read. */
49size_t det_client_available(int cid);
50
51/** @brief Drain up to @p cap buffered wire bytes into @p buf; returns the count. */
52size_t det_client_read(int cid, uint8_t *buf, size_t cap);
53
54/** @brief Tear down the connection (marshaled) and return the slot to the pool. */
55void det_client_close(int cid);
56
57#endif // DETERMINISTICESPASYNCWEBSERVER_DET_CLIENT_H
User-facing configuration for DeterministicESPAsyncWebServer.
bool det_client_connected(int cid)
True once the TCP handshake has completed for cid.
Definition client.cpp:314
bool det_client_send(int cid, const void *data, size_t len)
Queue len wire bytes for transmission (marshaled tcp_write + output).
Definition client.cpp:322
size_t det_client_available(int cid)
Wire bytes currently buffered and ready to read.
Definition client.cpp:326
bool det_client_is_closed(int cid)
True once the peer closed (FIN) or the connection errored.
Definition client.cpp:318
void det_client_close(int cid)
Tear down the connection (marshaled) and return the slot to the pool.
Definition client.cpp:334
size_t det_client_read(int cid, uint8_t *buf, size_t cap)
Drain up to cap buffered wire bytes into buf; returns the count.
Definition client.cpp:330
int det_client_open(const char *host, uint16_t port, uint32_t timeout_ms)
Resolve host (dotted-quad fast path, else DNS) and connect to host : port, blocking up to timeout_ms.
Definition client.cpp:310