cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
async_tls.c File Reference

Dispatch-thread record of a deferred-response handoff. More...

#include "async_internal.h"
#include <cwist/net/http/async.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for async_tls.c:

Go to the source code of this file.

Functions

void cwist_async_record_pending (cwist_async *a, const cwist_http_response *res)
 
void cwist_async_forget_handle (const cwist_async *a)
 
void cwist_async_forget_response (const cwist_http_response *res)
 
cwist_async * cwist_async_dispatch_take (cwist_http_response *res)
 
bool cwist_async_res_deferred (const cwist_http_response *res)
 

Detailed Description

Dispatch-thread record of a deferred-response handoff.

cwist_async_defer() records the handle it created here, on the dispatch thread. Dispatch decides the handoff from this record instead of res->deferred/res->async, which a producer on another thread can reach and overwrite before the ack (#344). Kept apart from async.c so that http.c and the middleware can use it without linking the completion machinery.

Definition in file async_tls.c.

Function Documentation

◆ cwist_async_dispatch_take()

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 cwist_async *  a)

Definition at line 43 of file async_tls.c.

References cap.

◆ 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_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.