1#define _POSIX_C_SOURCE 200809L
9#include "../../sys/io/reactor_rx.h"
17#include <sys/socket.h>
19#include <netinet/tcp.h>
35static bool app_use_https(
const cwist_app *app) {
46static void async_accept_dispatch(
cwist_app *app,
int client_fd) {
49 cwist_reactor_fd_forget(client_fd);
52#if defined(__linux__) && defined(TCP_QUICKACK)
57 if (app_use_https(app)) {
59 }
else if (app && !app->
use_ssl) {
64 "[async] SSL request accepted but HTTPS not ready (use_ssl=%d ssl_ctx=%p handler=%p), closing fd=%d\n",
66 app ? (
void *)app->https_request_handler :
NULL, client_fd);
80static void async_accept_cb(
int fd,
void *ctx);
99 async_accept_dispatch(
ac->app, fd);
119static void async_accept_cb(
int fd,
void *ctx) {
123#if defined(__linux__)
130 async_accept_dispatch(app, client_fd);
143 struct timespec ts = {.tv_sec = 0, .tv_nsec = 10 * 1000 * 1000};
148 "[async] FATAL: listen socket re-arm failed 1000x; this worker stopped accepting\n");
178 err.error.err_i16 = -1;
183 fprintf(
stderr,
"[async] Failed to init HTTPS thread pool\n");
190 fprintf(
stderr,
"[async] Failed to init HTTP thread pool\n");
197 perror(
"[async] Failed to set server socket non-blocking");
205#if defined(SO_REUSEPORT)
224#if defined(__linux__)
232#if defined(__linux__)
235 printf(
"[io_uring/SQPOLL] Kernel submission poller verified (0-syscall I/O enabled).\n");
239 printf(
"[io_uring/kqueue/epoll] Reactor started for C1M scale.\n");
252 err.error.err_i16 = 0;
Memory allocation wrappers backed by libttak.
cwist_error_t cwist_async_server_loop(int server_fd, cwist_app *app)
Run the async (reactor-based) HTTP/HTTPS server loop for C1M scale.
@ CWIST_ERR_INT16
used when checking common errcodes in Unix/Linux
HTTP/2 Protocol Definitions for CWIST.
bool cwist_reuseport_enabled(void)
HTTP Protocol Definitions and Helpers.
bool cwist_http_pool_submit_async(int client_fd, cwist_async_handler_t handler, void *ctx)
Submit a connection to the C1M async reactor pool.
void cwist_http_pool_destroy(void)
Tear down both pool variants.
int cwist_http_pool_init_mode(bool use_c1m)
Initialize the handler pool as reactor workers (use_c1m) or the classic thread pool,...
HTTPS/TLS wrapper interface.
void https_pool_destroy(void)
Shut down the global HTTPS thread pool: signal workers to exit, join them, close any connections stil...
int https_pool_init(void)
Create the worker threads, mutex, and condition variables of the global HTTPS thread pool....
void cwist_https_dispatch(int client_fd, cwist_https_context *ctx, void(*handler)(cwist_https_connection *, void *), void *user_ctx)
Accept a TLS connection without parking a worker on the handshake. Completes the handshake inline whe...
struct cwist_reactor cwist_reactor_t
bool cwist_reactor_add(cwist_reactor_t *reactor, int fd, cwist_reactor_cb_t cb, const void *payload, size_t payload_size)
void cwist_reactor_destroy(cwist_reactor_t *reactor)
void cwist_reactor_stop(cwist_reactor_t *reactor)
cwist_reactor_t * cwist_reactor_create(void)
void cwist_reactor_run(cwist_reactor_t *reactor)
Unified Graceful Shutdown support for CWIST.
int g_cwist_listen_fd
Registered TCP listening socket (for signal-handler closure).
atomic_int g_cwist_running
Global running flag. Checked by all server event loops.
Listen-socket option knobs shared by the bind sites (private).
Main Application Context.
cwist_https_context * ssl_ctx
SSL context when TLS is enabled.
cwist_https_request_handler_func https_request_handler
Integrated error structure used throughout the system.
Core Application Structure and Lifecycle Management.
cwist_async_action_t cwist_app_http_handler_async(int client_fd, cwist_http_async_conn_t *conn)
Zero-syscall I/O engine powered by Linux io_uring SQPOLL.