The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
worker.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 9472c2d0f1efb967ca0691fbaa48e872b52b58f4 $
20 *
21 * @file io/worker.h
22 * @brief Functions and data structures for worker threads.
23 *
24 * @copyright 2016 Alan DeKok (aland@freeradius.org)
25 */
26RCSIDH(worker_h, "$Id: 9472c2d0f1efb967ca0691fbaa48e872b52b58f4 $")
27
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*
34 * Network <-> Worker control message IDs
35 */
36#define FR_CONTROL_ID_LISTEN (2)
37#define FR_CONTROL_ID_WORKER (3)
38#define FR_CONTROL_ID_DIRECTORY (4)
39#define FR_CONTROL_ID_INJECT (5)
40#define FR_CONTROL_ID_LISTEN_DEAD (6)
41
42/**
43 * A data structure to track the worker.
44 *
45 * Once spawned, workers exist until they choose to exit.
46 */
47typedef struct fr_worker_s fr_worker_t;
48
49#ifdef __cplusplus
50}
51#endif
52
53#include <freeradius-devel/io/base.h>
54#include <freeradius-devel/server/command.h>
55#include <freeradius-devel/util/event.h>
56#include <freeradius-devel/util/heap.h>
57#include <freeradius-devel/util/log.h>
58#include <freeradius-devel/util/slab.h>
59#include <freeradius-devel/util/talloc.h>
60
61#include <pthread.h>
62
63#ifdef __cplusplus
64extern "C" {
65#endif
67
68typedef struct {
69 int max_requests; //!< max requests this worker will handle
70
71 int max_channels; //!< maximum number of channels
72
73 int message_set_size; //!< default start number of messages
74 int ring_buffer_size; //!< default start size for the ring buffers
75
76 fr_time_delta_t max_request_time; //!< maximum time a request can be processed
77
78 fr_slab_config_t reuse; //!< slab allocator configuration
80
82
83fr_worker_t *fr_worker_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, char const *name,
84 fr_log_t const *logger, fr_log_lvl_t lvl, fr_worker_config_t *config) CC_HINT(nonnull(2,3,4));
85
86void fr_worker_destroy(fr_worker_t *worker) CC_HINT(nonnull);
87
88void fr_worker(fr_worker_t *worker) CC_HINT(nonnull);
89
90void fr_worker_debug(fr_worker_t *worker, FILE *fp) CC_HINT(nonnull);
91
93
95
96fr_channel_t *fr_worker_channel_create(fr_worker_t *worker, TALLOC_CTX *ctx, fr_control_t *master) CC_HINT(nonnull);
97
98int fr_worker_stats(fr_worker_t const *worker, int num, uint64_t *stats) CC_HINT(nonnull);
99
100int fr_worker_listen_cancel(fr_worker_t *worker, fr_listen_t const *li);
101
102#include <freeradius-devel/server/module.h>
103
105
106#ifdef __cplusplus
107}
108#endif
#define RCSIDH(h, id)
Definition build.h:489
A full channel, which consists of two ends.
Definition channel.c:142
The control structure.
Definition control.c:76
Stores all information relating to an event list.
Definition event.c:377
fr_log_lvl_t
Definition log.h:64
static const conf_parser_t config[]
Definition base.c:163
static char const * name
Tuneable parameters for slabs.
Definition slab.h:42
Definition log.h:93
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
static fr_event_list_t * el
int nonnull(2, 5))
A worker which takes packets from a master, and processes them.
Definition worker.c:90
fr_channel_t * fr_worker_channel_create(fr_worker_t *worker, TALLOC_CTX *ctx, fr_control_t *master)
Create a channel to the worker.
Definition worker.c:1622
int message_set_size
default start number of messages
Definition worker.h:73
int fr_worker_subrequest_add(request_t *request)
fr_cmd_table_t cmd_worker_table[]
Definition worker.c:1753
int fr_worker_stats(fr_worker_t const *worker, int num, uint64_t *stats)
Definition worker.c:1698
int max_requests
max requests this worker will handle
Definition worker.h:69
int max_channels
maximum number of channels
Definition worker.h:71
int fr_worker_pre_event(fr_time_t now, fr_time_delta_t wake, void *uctx)
void fr_worker_destroy(fr_worker_t *worker)
Destroy a worker.
Definition worker.c:1010
void fr_worker_post_event(fr_event_list_t *el, fr_time_t now, void *uctx)
fr_worker_t * fr_worker_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, char const *name, fr_log_t const *logger, fr_log_lvl_t lvl, fr_worker_config_t *config))
Create a worker.
Definition worker.c:1350
int fr_worker_listen_cancel(fr_worker_t *worker, fr_listen_t const *li)
Definition worker.c:1649
int fr_worker_request_timeout_set(fr_worker_t *worker, request_t *request, fr_time_delta_t timeout)
void fr_worker(fr_worker_t *worker)
The main loop and entry point of the stand-alone worker thread.
Definition worker.c:1504
fr_slab_config_t reuse
slab allocator configuration
Definition worker.h:78
int ring_buffer_size
default start size for the ring buffers
Definition worker.h:74
fr_time_delta_t max_request_time
maximum time a request can be processed
Definition worker.h:76
void fr_worker_debug(fr_worker_t *worker, FILE *fp)
Print debug information about the worker structure.
Definition worker.c:1595