Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_network_accept_pool.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
27#ifndef __NILOREA_NETWORK_ACCEPT_POOL__
28#define __NILOREA_NETWORK_ACCEPT_POOL__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
99#include "n_common.h"
100#include "n_network.h"
101#include "n_thread_pool.h"
102
103#include <time.h>
104
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
113
118typedef void (*netw_accept_callback_t)(NETWORK* accepted, void* user_data);
119
133
156
158#define netw_accept_pool_atomic_read_state(pool) __atomic_load_n(&(pool)->state, __ATOMIC_ACQUIRE)
159
161#define netw_accept_pool_atomic_write_state(pool, val) __atomic_store_n(&(pool)->state, (val), __ATOMIC_RELEASE)
162
164NETW_ACCEPT_POOL* netw_accept_pool_create(NETWORK* server, size_t nb_threads, int accept_timeout, netw_accept_callback_t callback, void* user_data);
165
168
171
173int netw_accept_pool_wait(NETW_ACCEPT_POOL* pool, int timeout_sec);
174
177
180
183#ifdef __cplusplus
184}
185#endif
186
187#endif /* __NILOREA_NETWORK_ACCEPT_POOL__ */
static NETWORK_POOL * pool
NETWORK * server
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.
Structure of a NETWORK.
Definition n_network.h:258
Common headers and low-level functions & define.
Network Engine.
Thread pool declaration.