DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
client.h File Reference

Layer 4 outbound TCP client transport - the client-side peer of the (server) transport in tcp.cpp. More...

#include "ServerConfig.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

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.
 
bool det_client_connected (int cid)
 True once the TCP handshake has completed for cid.
 
bool det_client_is_closed (int cid)
 True once the peer closed (FIN) or the connection errored.
 
bool det_client_send (int cid, const void *data, size_t len)
 Queue len wire bytes for transmission (marshaled tcp_write + output).
 
size_t det_client_available (int cid)
 Wire bytes currently buffered and ready to read.
 
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.
 
void det_client_close (int cid)
 Tear down the connection (marshaled) and return the slot to the pool.
 

Detailed Description

Layer 4 outbound TCP client transport - the client-side peer of the (server) transport in tcp.cpp.

A small fixed pool of outbound connections so the application's clients (services/http_client, services/mqtt, services/ws_client) no longer each own a private raw-lwIP TCP stack at L7. As with the server transport, every raw tcp_*() call is marshaled into tcpip_thread via tcpip_api_call(), so the main-loop/worker task never races the stack. All storage is static (no heap).

The receive ring carries wire bytes: for a plaintext connection those are the application bytes; for a TLS connection they are ciphertext and the caller layers the shared client-TLS session (det_tls_csess_*) on top, pointing its BIO at det_client_send() / det_client_read().

The core is non-blocking (read/available/send), so it suits both a polling client loop (MQTT, WebSocket) and a blocking request (HTTP) that drives its own deadline. Only det_client_open() blocks, on DNS + connect.

Definition in file client.h.

Function Documentation

◆ det_client_open()

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.

Returns
A client id in [0, DETWS_CLIENT_CONNS) on success, or < 0 on failure (pool full, DNS failure, connect timeout/refused).

Definition at line 310 of file client.cpp.

◆ det_client_connected()

bool det_client_connected ( int  cid)

True once the TCP handshake has completed for cid.

Definition at line 314 of file client.cpp.

◆ det_client_is_closed()

bool det_client_is_closed ( int  cid)

True once the peer closed (FIN) or the connection errored.

Definition at line 318 of file client.cpp.

◆ det_client_send()

bool det_client_send ( int  cid,
const void *  data,
size_t  len 
)

Queue len wire bytes for transmission (marshaled tcp_write + output).

Definition at line 322 of file client.cpp.

◆ det_client_available()

size_t det_client_available ( int  cid)

Wire bytes currently buffered and ready to read.

Definition at line 326 of file client.cpp.

◆ det_client_read()

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 at line 330 of file client.cpp.

◆ det_client_close()

void det_client_close ( int  cid)

Tear down the connection (marshaled) and return the slot to the pool.

Definition at line 334 of file client.cpp.