The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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: ddf0f29e17efa34776a213ded041367f0b70c99b $
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: ddf0f29e17efa34776a213ded041367f0b70c99b $")
27
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/** Events for a worker's own control messages, in the FR_CONTROL_EVENTSET_WORKER event set
34 */
36 FR_WORKER_CONTROL_LISTEN_DEAD = 0 //!< A listener has been closed.
38
39/**
40 * A data structure to track the worker.
41 *
42 * Once spawned, workers exist until they choose to exit.
43 */
44typedef struct fr_worker_s fr_worker_t;
45
46#ifdef __cplusplus
47}
48#endif
49
50#include <freeradius-devel/io/base.h>
51#include <freeradius-devel/server/command.h>
52#include <freeradius-devel/util/event.h>
53#include <freeradius-devel/util/heap.h>
54#include <freeradius-devel/util/log.h>
55#include <freeradius-devel/util/slab.h>
56#include <freeradius-devel/util/talloc.h>
57
58#include <pthread.h>
59
60#ifdef __cplusplus
61extern "C" {
62#endif
64
65typedef struct {
66 int max_requests; //!< max requests this worker will handle
67
68 int max_channels; //!< maximum number of channels
69
70 int message_set_size; //!< default start number of messages
71 int ring_buffer_size; //!< default start size for the ring buffers
72
73 fr_time_delta_t max_request_time; //!< maximum time a request can be processed
74
75 fr_slab_config_t reuse; //!< slab allocator configuration
77
79
80fr_worker_t *fr_worker_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, char const *name,
81 fr_log_t const *logger, fr_log_lvl_t lvl, fr_worker_config_t *config) CC_HINT(nonnull(2,3,4));
82
84
85void fr_worker_shutting_down(fr_worker_t *worker) CC_HINT(nonnull);
86
87void fr_worker_exit(fr_worker_t *worker);
88
89void fr_worker(fr_worker_t *worker) CC_HINT(nonnull);
90
91void fr_worker_debug(fr_worker_t *worker, FILE *fp) CC_HINT(nonnull);
92
94
96
97fr_channel_t *fr_worker_channel_create(fr_worker_t *worker, TALLOC_CTX *ctx, fr_control_t *master,
98 fr_message_set_t *reply_ms) CC_HINT(nonnull);
99
100int fr_worker_stats(fr_worker_t const *worker, int num, uint64_t *stats) CC_HINT(nonnull);
101
103
105
106#include <freeradius-devel/server/module.h>
107
109
110#ifdef __cplusplus
111}
112#endif
static uint8_t request[4]
#define RCSIDH(h, id)
Definition build.h:604
A full channel, which consists of two ends.
Definition channel.c:129
The control structure.
Definition control.c:211
Stores all information relating to an event list.
Definition event.c:375
fr_log_lvl_t
Definition log.h:64
unsigned short uint16_t
A Message set, composed of message headers and ring buffer data.
Definition message.c:94
static const conf_parser_t config[]
Definition base.c:162
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:89
fr_channel_t * fr_worker_channel_create(fr_worker_t *worker, TALLOC_CTX *ctx, fr_control_t *master, fr_message_set_t *reply_ms)
Create a channel to the worker.
Definition worker.c:1653
int message_set_size
default start number of messages
Definition worker.h:70
int fr_worker_subrequest_add(request_t *request)
fr_cmd_table_t cmd_worker_table[]
Definition worker.c:1784
int fr_worker_stats(fr_worker_t const *worker, int num, uint64_t *stats)
Definition worker.c:1724
fr_worker_control_event_t
Events for a worker's own control messages, in the FR_CONTROL_EVENTSET_WORKER event set.
Definition worker.h:35
@ FR_WORKER_CONTROL_LISTEN_DEAD
A listener has been closed.
Definition worker.h:36
int max_requests
max requests this worker will handle
Definition worker.h:66
int max_channels
maximum number of channels
Definition worker.h:68
int fr_worker_pre_event(fr_time_t now, fr_time_delta_t wake, void *uctx)
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:1260
void fr_worker_shutting_down(fr_worker_t *worker)
Tell the interpreter of the worker to cancel requests, instead of running them.
Definition worker.c:1602
int fr_worker_listen_cancel(fr_worker_t *worker, fr_listen_instance_t const *li)
Definition worker.c:1680
int fr_worker_request_timeout_set(fr_worker_t *worker, request_t *request, fr_time_delta_t timeout)
int fr_worker_close_event_insert(fr_worker_t *worker)
Add events to the loop which will send close ack to the network.
Definition worker.c:1581
void fr_worker(fr_worker_t *worker)
The main loop and entry point of the stand-alone worker thread.
Definition worker.c:1463
fr_worker_config_t const * fr_worker_config(fr_worker_t *worker)
Definition worker.c:1741
fr_slab_config_t reuse
slab allocator configuration
Definition worker.h:75
int ring_buffer_size
default start size for the ring buffers
Definition worker.h:71
void fr_worker_exit(fr_worker_t *worker)
Tidy up a worker on normal exit.
Definition worker.c:970
fr_time_delta_t max_request_time
maximum time a request can be processed
Definition worker.h:73
void fr_worker_debug(fr_worker_t *worker, FILE *fp)
Print debug information about the worker structure.
Definition worker.c:1625