fix: transparently support blocking work without worker threads

This commit is contained in:
Jef Roosens 2024-02-14 12:43:58 +01:00
parent 1b8ba305b5
commit 1f63f06e0c
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
8 changed files with 62 additions and 46 deletions

View file

@ -32,23 +32,16 @@ lnm_err lnm_http_loop_init(lnm_http_loop **out, void *c_gctx,
lnm_http_ctx_reset_fn ctx_reset,
lnm_http_ctx_free_fn ctx_free);
/**
* Initialize a new step.
*
* @param out where to store pointer to new `lnm_http_step`
* @param fn step function
*/
lnm_err lnm_http_step_init(lnm_http_step **out, lnm_http_step_fn fn);
/**
* Append the given step fn to the step.
*
* @param out where to store pointer to new `lnm_http_step`
* @param step step to append new step to
* @param out both the previous step to append the new step to, and the output
* variable to which the new step is appended
* @param fn step function
* @param blocking whether the step is blocking or not
*/
lnm_err lnm_http_step_append(lnm_http_step **out, lnm_http_step *step,
lnm_http_step_fn fn);
lnm_err lnm_http_step_append(lnm_http_step **out, lnm_http_step_fn fn,
bool blocking);
/**
* Initialize a new route of type literal.

View file

@ -106,6 +106,26 @@ lnm_err lnm_loop_run(lnm_loop *l);
lnm_err lnm_loop_run_multi(lnm_loop *l, size_t epoll_threads,
size_t worker_threads);
/**
* Advance the processing of the given connection.
*
* Behavior of this function depends on both the connection state and whether
* worker threads are enabled.
*
* For IO states, this function will perform network I/O along with executing
* the loop's respective processing functions.
*
* For work states, the respective processing functions are executed without
* performing any network I/O. If no worker queue is present, this function
* performs all blocking work until an I/O or the end state is reached. If there
* is a worker queue present, only one block of work is done before exiting,
* allowing further blocks of work to be scheduled on other worker threads.
*
* If no worker queue is present, this function will only exit once an I/O or
* end state is reached.
*/
void lnm_loop_conn_advance(lnm_loop *l, lnm_loop_conn *conn);
/**
* Reschedule the given connection, either on the event loop for network IO or
* on a worker thread for blocking work. Connections are terminated as needed.