cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
async_internal.h File Reference

Private wiring between the deferred-response path (async.c) and the C1M connection engine (http.c). More...

#include <cwist/net/http/http.h>
#include <cwist/sys/io/reactor.h>
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for async_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint64_t cwist_http_reactor_generation (void)
 Return the current reactor generation counter.
 
bool cwist_http_reactor_post_live (cwist_reactor_t *reactor, uint64_t gen, cwist_reactor_post_t *node)
 Post a reactor node only while the captured generation is current.
 
void cwist_http_async_close_orphan (int client_fd, cwist_http_async_conn_t *conn)
 Close an async connection whose owning worker pool is gone.
 
bool cwist_async_https_take_deferred (void)
 
void cwist_async_record_pending (struct cwist_async *a, const cwist_http_response *res)
 
void cwist_async_forget_handle (const struct cwist_async *a)
 
struct cwist_async * cwist_async_dispatch_take (cwist_http_response *res)
 
bool cwist_async_res_deferred (const cwist_http_response *res)
 
void cwist_async_forget_response (const cwist_http_response *res)
 

Detailed Description

Private wiring between the deferred-response path (async.c) and the C1M connection engine (http.c).

Definition in file async_internal.h.

Function Documentation

◆ cwist_async_dispatch_take()

struct cwist_async * cwist_async_dispatch_take ( cwist_http_response *  res)

Dispatch side of the handoff: return the handle cwist_async_defer() created for res on this thread, or NULL if the handler did not defer it, and forget it. Dispatch calls this right after the handler returns and uses the result instead of res->deferred/res->async, which a producer can reach and overwrite before the ack. A mismatch between the two is reported (and aborts under CWIST_ASYNC_STRICT=1).

Definition at line 57 of file async_tls.c.

References cwist_http_response::async, cap, and cwist_http_response::deferred.

Referenced by cwist_http2_serve_connection_ex().

◆ cwist_async_forget_handle()

void cwist_async_forget_handle ( const struct cwist_async *  a)

Drop this thread's record if it names a (ack, final release).

Referenced by cwist_async_dispatch_ack(), and cwist_async_release().

◆ cwist_async_forget_response()

void cwist_async_forget_response ( const cwist_http_response *  res)

Drop this thread's pending handoff if it names res, so a response later allocated at the same address is not mistaken for it. Called when a response is destroyed without dispatch having taken it (a defer outside dispatch, or a path such as HTTP/3 that does not hand off).

Definition at line 50 of file async_tls.c.

References cap.

Referenced by cwist_http_response_destroy().

◆ cwist_async_https_take_deferred()

bool cwist_async_https_take_deferred ( void  )

Return whether cwist_async_defer() handed an HTTP/1.1 HTTPS connection to its completion on this thread since the last call, and clear the flag (deferring an h2 stream leaves the conn with the h2 loop). The HTTPS pool worker checks this instead of conn->deferred: once the dispatch ack is published the completion owns the conn and may already have closed or resubmitted it.

Definition at line 97 of file async.c.

◆ cwist_async_record_pending()

void cwist_async_record_pending ( struct cwist_async *  a,
const cwist_http_response *  res 
)

Record that a now owns res; called by cwist_async_defer().

Definition at line 38 of file async_tls.c.

References cap.

Referenced by cwist_async_defer().

◆ cwist_async_res_deferred()

bool cwist_async_res_deferred ( const cwist_http_response *  res)

Return whether res is deferred as seen from this thread: either cwist_async_defer() deferred it here and dispatch has not taken it yet, or res->deferred is set. Middleware uses this so a producer that clears res->deferred early cannot make the dispatch thread touch the response.

Definition at line 71 of file async_tls.c.

References cwist_http_response::deferred.

◆ cwist_http_async_close_orphan()

void cwist_http_async_close_orphan ( int  client_fd,
cwist_http_async_conn_t *  conn 
)

Close an async connection whose owning worker pool is gone.

Close a deferred connection whose worker reactor is gone: close client_fd and release conn without touching the worker load counters.

Marks the load slot index invalid so the teardown does not touch load counters that may belong to a later pool generation.

Definition at line 1453 of file http.c.

References cap, and cwist_http_async_conn::worker_id.

◆ cwist_http_reactor_generation()

uint64_t cwist_http_reactor_generation ( void  )

Return the current reactor generation counter.

Current generation of the C1M worker reactors; changes when the pool is destroyed.

Deferred completions capture the generation so they can detect pool teardown; see g_reactor_gen for the protocol.

Definition at line 268 of file http.c.

References cap.

Referenced by cwist_async_defer().

◆ cwist_http_reactor_post_live()

bool cwist_http_reactor_post_live ( cwist_reactor_t *  reactor,
uint64_t  gen,
cwist_reactor_post_t *  node 
)

Post a reactor node only while the captured generation is current.

Post node to reactor only while the reactor still belongs to generation gen. Returns false, without posting, once the pool that owned it has been destroyed.

Counts the caller in g_reactor_posters around the generation check and the post so cwist_http_pool_destroy() cannot free the reactor in between.

Parameters
reactorReactor to post into.
genGeneration the completion was created under.
nodePost node to enqueue.
Returns
true when the node was posted; false when the generation moved or the post failed (the caller must close instead).

Definition at line 283 of file http.c.

References cap.