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 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
28#ifndef __NILOREA_NETWORK_ACCEPT_POOL__
29#define __NILOREA_NETWORK_ACCEPT_POOL__
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
100#include "n_common.h"
101#include "n_network.h"
102#include "n_thread_pool.h"
103
104#include <time.h>
105
107#define NETW_ACCEPT_POOL_IDLE 0
109#define NETW_ACCEPT_POOL_RUNNING 1
111#define NETW_ACCEPT_POOL_STOPPING 2
113#define NETW_ACCEPT_POOL_STOPPED 3
114
119typedef void (*netw_accept_callback_t)(NETWORK* accepted, void* user_data);
120
134
157
159#define netw_accept_pool_atomic_read_state(pool) __atomic_load_n(&(pool)->state, __ATOMIC_ACQUIRE)
160
162#define netw_accept_pool_atomic_write_state(pool, val) __atomic_store_n(&(pool)->state, (val), __ATOMIC_RELEASE)
163
165NETW_ACCEPT_POOL* netw_accept_pool_create(NETWORK* server, size_t nb_threads, int accept_timeout, netw_accept_callback_t callback, void* user_data);
166
169
172
174int netw_accept_pool_wait(NETW_ACCEPT_POOL* pool, int timeout_sec);
175
178
181
184#ifdef __cplusplus
185}
186#endif
187
188#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:309
Common headers and low-level functions & define.
Network Engine.
Thread pool declaration.