27#ifndef __NILOREA_NETWORK_ACCEPT_POOL__
28#define __NILOREA_NETWORK_ACCEPT_POOL__
106#define NETW_ACCEPT_POOL_IDLE 0
108#define NETW_ACCEPT_POOL_RUNNING 1
110#define NETW_ACCEPT_POOL_STOPPING 2
112#define NETW_ACCEPT_POOL_STOPPED 3
158#define netw_accept_pool_atomic_read_state(pool) __atomic_load_n(&(pool)->state, __ATOMIC_ACQUIRE)
161#define netw_accept_pool_atomic_write_state(pool, val) __atomic_store_n(&(pool)->state, (val), __ATOMIC_RELEASE)
static NETWORK_POOL * pool
netw_accept_callback_t callback
user callback invoked on each accepted connection
pthread_t * accept_threads
array of pthread ids
size_t total_errors
total accept errors
size_t nb_accept_threads
number of accept threads
void * user_data
opaque user data passed to callback
struct timespec start_time
time when pool was started (CLOCK_MONOTONIC)
size_t active_threads
number of accept threads currently running
size_t total_timeouts
total accept timeouts (no connection available)
size_t total_accepted
total connections successfully accepted
int accept_timeout
accept timeout in milliseconds (passed to netw_accept_from_ex blocking param).
NETW_ACCEPT_POOL_STATS stats
pool statistics
NETWORK * server
listening socket (not owned, caller must keep alive)
uint32_t state
atomic pool state
pthread_mutex_t stats_lock
mutex protecting stats
void(* netw_accept_callback_t)(NETWORK *accepted, void *user_data)
callback type for accepted connections.
NETW_ACCEPT_POOL * netw_accept_pool_create(NETWORK *server, size_t nb_threads, int accept_timeout, netw_accept_callback_t callback, void *user_data)
Create a new accept pool.
int netw_accept_pool_get_stats(NETW_ACCEPT_POOL *pool, NETW_ACCEPT_POOL_STATS *stats)
Get a snapshot of pool statistics (thread-safe copy)
int netw_accept_pool_wait(NETW_ACCEPT_POOL *pool, int timeout_sec)
Wait for all accept threads to finish after a stop request.
int netw_accept_pool_destroy(NETW_ACCEPT_POOL **pool)
Destroy an accept pool.
int netw_accept_pool_stop(NETW_ACCEPT_POOL *pool)
Request the accept pool to stop.
int netw_accept_pool_start(NETW_ACCEPT_POOL *pool)
Start the accept pool (launches accept threads)
Structure of a parallel accept pool.
Statistics for the accept pool.
Common headers and low-level functions & define.