cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
compat.c
Go to the documentation of this file.
1
17#if defined(__wasi__)
18
19#include <cwist/sys/wasi.h>
25#include <cwist/net/grpc/grpc.h>
26
27#include <stddef.h>
28#include <stdint.h>
29#include <sys/uio.h>
30
31/* --- Reactor: no event loop exists outside the process runtime. --------- */
32
38 return NULL;
39}
40
50bool cwist_reactor_mod(cwist_reactor_t *reactor, int fd, cwist_reactor_cb_t cb, const void *payload,
51 size_t payload_size) {
52 (void)reactor;
53 (void)fd;
54 (void)cb;
55 (void)payload;
57 return false;
58}
59
66bool cwist_reactor_del(cwist_reactor_t *reactor, int fd) {
67 (void)reactor;
68 (void)fd;
69 return false;
70}
71
77 (void)reactor;
78}
79
89bool cwist_reactor_add(cwist_reactor_t *reactor, int fd, cwist_reactor_cb_t cb, const void *payload,
90 size_t payload_size) {
91 (void)reactor;
92 (void)fd;
93 (void)cb;
94 (void)payload;
96 return false;
97}
98
109 const void *payload, size_t payload_size) {
110 (void)reactor;
111 (void)fd;
112 (void)cb;
113 (void)payload;
115 return false;
116}
117
125 (void)reactor;
126 (void)node;
127 return false;
128}
129
134void cwist_reactor_stop(cwist_reactor_t *reactor) {
135 (void)reactor;
136}
137
143 (void)reactor;
144}
145
146void cwist_reactor_timer_init(cwist_reactor_timer_t *timer, void (*cb)(void *ctx), void *ctx) {
147 if (!timer) return;
148 timer->deadline_ns = 0;
149 timer->heap_slot = 0;
150 timer->cb = cb;
151 timer->ctx = ctx;
152}
153
156 (void)reactor;
157 (void)timer;
158 (void)delay_us;
159 return false;
160}
161
163 (void)reactor;
164 (void)timer;
165}
166
168 (void)timer;
169 return false;
170}
171
172/* --- Metrics / parked-writer fast paths: under WASI 0.2 the real
173 * metrics.c and writer_fast.c join the build, so these stubs exist only
174 * for preview1 where those units cannot compile. ------------------------ */
175#ifndef CWIST_WASI_SOCKETS
178
185 return g_wasi_metrics_sink;
186}
187
194 (void)reg;
195 (void)id;
196}
197
203 return 0;
204}
205
216 int flags, size_t *total_sent) {
217 (void)fd;
218 (void)iov;
219 (void)iovcnt;
220 (void)flags;
221 if (total_sent) *total_sent = 0;
222 return CWIST_WRITE_ERR;
223}
224#endif /* !CWIST_WASI_SOCKETS */
225
226/* --- HTTPS/HTTP-2 upgrade paths: no TLS in a WASM host. ----------------- */
227
234 (void)conn;
235 return false;
236}
237
244 (void)conn;
245 return NULL;
246}
247
258 const cwist_http2_stream_hooks *hooks) {
259 (void)conn;
260 (void)user_ctx;
261 (void)handler;
262 (void)hooks;
263 cwist_error_t err = {0};
264 err.error.err_i16 = -1;
265 return err;
266}
267
273 return NULL;
274}
275
276/* H2 deferred-completion queue: reachable through async.c's Plan B handoff,
277 * but a WASM host never runs an H2 connection, so req->h2_queue is always
278 * NULL on this target and the stubs are never executed. */
284cwist_h2_async_queue *cwist_h2_async_queue_acquire(cwist_h2_async_queue *q) {
285 return q;
286}
287
292void cwist_h2_async_queue_release(cwist_h2_async_queue *q) {
293 (void)q;
294}
295
306int cwist_h2_async_queue_enqueue(cwist_h2_async_queue *q, uint32_t stream_id,
308 cwist_http_response *res, bool send_owned) {
309 (void)q;
310 (void)stream_id;
311 (void)req;
312 (void)send;
313 (void)res;
314 (void)send_owned;
315 return -1;
316}
317
318/* HTTPS connection send/close: reachable through async.c's completion path,
319 * never executed -- a WASM host dispatches in memory and never wraps a TLS
320 * connection. */
326 (void)conn;
327}
328
335 cwist_error_t err = {0};
336 err.error.err_i16 = -1;
337 return err;
338}
339
347 (void)conn;
348 (void)res;
350}
351
359 cwist_http_response *res) {
360 (void)conn;
361 (void)res;
363}
364
373 void (*handler)(cwist_https_connection *, void *), void *user_ctx) {
374 (void)conn;
375 (void)ctx;
376 (void)handler;
377 (void)user_ctx;
378}
379
380#endif /* __wasi__ */
gRPC over HTTP/2 helpers for CWIST.
const cwist_http2_stream_hooks * cwist_grpc_http2_hooks(void)
Access the gRPC HTTP/2 stream hooks table.
Definition grpc.c:2109
HTTP/2 Protocol Definitions for CWIST.
cwist_h2_async_queue * cwist_h2_async_queue_acquire(cwist_h2_async_queue *q)
Take an additional reference on the queue (for an in-flight cwist_async handle).
Definition http2.c:316
cwist_error_t cwist_http2_serve_connection_ex(cwist_https_connection *conn, void *user_ctx, cwist_http2_request_handler_func handler, const cwist_http2_stream_hooks *hooks)
Serve one HTTP/2 connection until it closes. Verifies the preface, sends our SETTINGS,...
Definition http2.c:3573
int cwist_h2_async_queue_enqueue(cwist_h2_async_queue *q, uint32_t stream_id, cwist_http_request *req, cwist_http_response *send, cwist_http_response *res, bool send_owned)
Definition http2.c:339
void cwist_h2_async_queue_release(cwist_h2_async_queue *q)
Drop a reference on the queue. On the last reference: closes the wake descriptors,...
Definition http2.c:327
struct cwist_h2_async_queue cwist_h2_async_queue
Definition http2.h:123
void(* cwist_http2_request_handler_func)(void *user_ctx, cwist_http_request *req, cwist_http_response *res)
Callback function type for handling HTTP/2 requests.
Definition http2.h:19
cwist_http_request * cwist_https_receive_request(cwist_https_connection *conn)
Read from the TLS stream until a full HTTP request has been assembled.
Definition https.c:1887
cwist_error_t cwist_https_send_response(cwist_https_connection *conn, cwist_http_response *res)
Serialize an HTTP response and send it over an active TLS connection.
Definition https.c:2102
void cwist_https_close_connection(cwist_https_connection *conn)
Definition https.c:1875
Production-grade metrics engine for CWIST.
cwist_metrics_registry_t * cwist_metrics_registry(void)
Obtain the global registry, creating it on first call.
Definition metrics.c:112
enum cwist_metric_id cwist_metric_id_t
Pre-defined framework metrics.
struct cwist_metrics_registry cwist_metrics_registry_t
Global metrics registry (singleton, lazy-initialised).
Definition metrics.h:87
void cwist_metric_inc(cwist_metrics_registry_t *reg, cwist_metric_id_t id)
Increment a counter metric by 1.
Definition metrics.c:179
HTTPS/TLS wrapper interface.
void https_pool_submit_conn(cwist_https_connection *conn, cwist_https_context *ctx, void(*handler)(cwist_https_connection *, void *), void *user_ctx)
Submit an established connection back to the worker pool (e.g. keep-alive re-arm after async defer)....
Definition https.c:341
cwist_error_t cwist_https_send_response_head(cwist_https_connection *conn, cwist_http_response *res)
Definition https.c:2197
bool cwist_https_connection_uses_http2(const cwist_https_connection *conn)
Gracefully close an HTTPS connection and free its buffers.
Definition https.c:1817
size_t cap
Definition otel.c:56
struct cwist_reactor cwist_reactor_t
Definition reactor.h:14
bool cwist_reactor_timer_arm(cwist_reactor_t *reactor, cwist_reactor_timer_t *timer, uint64_t delay_us)
Definition reactor.c:937
bool cwist_reactor_add(cwist_reactor_t *reactor, int fd, cwist_reactor_cb_t cb, const void *payload, size_t payload_size)
Definition reactor.c:1357
void cwist_reactor_timer_init(cwist_reactor_timer_t *timer, void(*cb)(void *ctx), void *ctx)
Definition reactor.c:929
bool cwist_reactor_del(cwist_reactor_t *reactor, int fd)
Definition reactor.c:1410
void(* cwist_reactor_cb_t)(int fd, void *ctx)
Definition reactor.h:12
void cwist_reactor_destroy(cwist_reactor_t *reactor)
Definition reactor.c:1116
void cwist_reactor_stop(cwist_reactor_t *reactor)
Definition reactor.c:1904
cwist_reactor_t * cwist_reactor_create(void)
Definition reactor.c:1006
void cwist_reactor_run(cwist_reactor_t *reactor)
Definition reactor.c:1579
bool cwist_reactor_mod(cwist_reactor_t *reactor, int fd, cwist_reactor_cb_t cb, const void *payload, size_t payload_size)
Definition reactor.c:1367
bool cwist_reactor_timer_armed(const cwist_reactor_timer_t *timer)
Definition reactor.c:961
void cwist_reactor_timer_cancel(cwist_reactor_t *reactor, cwist_reactor_timer_t *timer)
Definition reactor.c:956
bool cwist_reactor_add_out(cwist_reactor_t *reactor, int fd, cwist_reactor_cb_t cb, const void *payload, size_t payload_size)
Definition reactor.c:1362
Integrated error structure used throughout the system.
Definition cwist_err.h:72
__prim_cwist_error_t error
Definition cwist_err.h:74
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
Definition http.h:82
Definition reactor.h:46
uint64_t deadline_ns
Definition reactor.h:63
uint32_t heap_slot
Definition reactor.h:64
void(* cb)(void *ctx)
Definition reactor.h:65
WASI target feature detection shared by all CWIST sources.
Zero-latency speculative fast-path writer and P2C worker scheduler.
cwist_write_status_t
Definition writer_fast.h:24
@ CWIST_WRITE_ERR
Definition writer_fast.h:29
cwist_write_status_t cwist_http_sendmsg_speculative(int fd, struct iovec *iov, int iovcnt, int flags, size_t *total_sent)
Speculative scatter/gather sendmsg without blocking poll().
Definition writer_fast.c:83
uint32_t cwist_fast_monotonic_sec(void)
Fast monotonic clock in seconds (vDSO coarse where available).