![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <getopt.h>#include <signal.h>#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_network.h"#include "nilorea/n_network_accept_pool.h"#include "nilorea/n_thread_pool.h"
Include dependency graph for ex_accept_pool_server.c:Go to the source code of this file.
Data Structures | |
| struct | CALLBACK_DATA |
| data passed to accept callback and worker threads More... | |
| struct | WORKER_ARG |
| data passed to worker thread function More... | |
Macros | |
| #define | MODE_POOLED 2 |
| #define | MODE_SINGLE_INLINE 0 |
| mode constants | |
| #define | MODE_SINGLE_POOL 1 |
Functions | |
| static void | dispatch_to_pool (NETWORK *client, CALLBACK_DATA *cb_data) |
| Dispatch a client to the thread pool for handling. | |
| static void | handle_client (NETWORK *client) |
| Handle a single client: read one message, echo it back, close. | |
| static void | handle_inline_and_count (NETWORK *client, CALLBACK_DATA *cb_data) |
| Handle client inline in the accept thread and update counter. | |
| int | main (int argc, char **argv) |
| static void | on_accept_pooled (NETWORK *conn, void *user_data) |
| Accept pool callback: dispatches to thread pool. | |
| static void | sighandler (int sig) |
| static void | usage (void) |
| static void * | worker_handle_client (void *ptr) |
| Worker thread function: handles a client and updates counter. | |
Variables | |
| static volatile int | server_running = 1 |
| static int | total_target = 500 |
| struct CALLBACK_DATA |
data passed to accept callback and worker threads
Definition at line 80 of file ex_accept_pool_server.c.
Collaboration diagram for CALLBACK_DATA:| Data Fields | ||
|---|---|---|
| size_t | handled | atomic counter of handled connections |
| pthread_mutex_t | lock | mutex for counter |
| THREAD_POOL * | worker_pool | thread pool for dispatching (modes single-pool and pooled) |
| struct WORKER_ARG |
data passed to worker thread function
Definition at line 108 of file ex_accept_pool_server.c.
Collaboration diagram for WORKER_ARG:| Data Fields | ||
|---|---|---|
| CALLBACK_DATA * | cb_data | back pointer to callback data for counting |
| NETWORK * | client | the accepted connection |
| #define MODE_POOLED 2 |
Definition at line 77 of file ex_accept_pool_server.c.
| #define MODE_SINGLE_INLINE 0 |
mode constants
Definition at line 75 of file ex_accept_pool_server.c.
| #define MODE_SINGLE_POOL 1 |
Definition at line 76 of file ex_accept_pool_server.c.
|
static |
Dispatch a client to the thread pool for handling.
| client | the accepted NETWORK connection |
| cb_data | callback data with thread pool and counters |
Definition at line 144 of file ex_accept_pool_server.c.
References __n_assert, add_threaded_process(), LOG_ERR, Malloc, n_log, netw_close(), NORMAL_PROC, worker_handle_client(), and CALLBACK_DATA::worker_pool.
Referenced by main(), and on_accept_pooled().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Handle a single client: read one message, echo it back, close.
| client | the accepted NETWORK connection |
Definition at line 93 of file ex_accept_pool_server.c.
References __n_assert, netw_add_msg(), netw_close(), netw_start_thr_engine(), netw_wait_msg(), and u_sleep().
Referenced by handle_inline_and_count(), and worker_handle_client().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Handle client inline in the accept thread and update counter.
| client | the accepted NETWORK connection |
| cb_data | callback data with counters |
Definition at line 167 of file ex_accept_pool_server.c.
References __n_assert, handle_client(), CALLBACK_DATA::handled, CALLBACK_DATA::lock, LOG_NOTICE, n_log, and netw_close().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 210 of file ex_accept_pool_server.c.
References NETW_ACCEPT_POOL_STATS::active_threads, addr, destroy_threaded_pool(), dispatch_to_pool(), FreeNoLog, handle_inline_and_count(), CALLBACK_DATA::handled, LOG_DEBUG, LOG_ERR, LOG_INFO, log_level, LOG_NOTICE, mode, MODE_POOLED, MODE_SINGLE_INLINE, MODE_SINGLE_POOL, n_log, netw_accept_from_ex(), netw_accept_pool_create(), netw_accept_pool_destroy(), netw_accept_pool_get_stats(), netw_accept_pool_start(), netw_accept_pool_stop(), netw_accept_pool_wait(), netw_close(), netw_make_listening(), NETWORK_IPALL, new_thread_pool(), on_accept_pooled(), port, server, server_running, set_log_level(), sighandler(), NETW_ACCEPT_POOL_STATS::total_accepted, NETW_ACCEPT_POOL_STATS::total_errors, total_target, NETW_ACCEPT_POOL_STATS::total_timeouts, u_sleep(), usage(), and wait_for_threaded_pool().
Here is the call graph for this function:
|
static |
Accept pool callback: dispatches to thread pool.
| conn | the accepted NETWORK connection |
| user_data | pointer to CALLBACK_DATA |
Definition at line 187 of file ex_accept_pool_server.c.
References __n_assert, dispatch_to_pool(), and netw_close().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 193 of file ex_accept_pool_server.c.
References server_running.
Referenced by main().
Here is the caller graph for this function:
|
static |
Definition at line 198 of file ex_accept_pool_server.c.
|
static |
Worker thread function: handles a client and updates counter.
| ptr | pointer to WORKER_ARG (freed by this function) |
Definition at line 120 of file ex_accept_pool_server.c.
References __n_assert, WORKER_ARG::cb_data, WORKER_ARG::client, Free, handle_client(), CALLBACK_DATA::handled, CALLBACK_DATA::lock, LOG_NOTICE, and n_log.
Referenced by dispatch_to_pool().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 71 of file ex_accept_pool_server.c.
Referenced by main(), and sighandler().
|
static |
Definition at line 72 of file ex_accept_pool_server.c.
Referenced by main().