23 RCSID(
"$Id: 56090248a9985bfab00f5c40c10640efdb06c25f $")
25 #include <freeradius-devel/io/control.h>
26 #include <freeradius-devel/util/debug.h>
27 #include <freeradius-devel/util/syserror.h>
28 #include <freeradius-devel/util/talloc.h>
29 #include <freeradius-devel/util/time.h>
31 #include <sys/event.h>
41 #define MEM(x) if (!(x)) { fprintf(stderr, "%s[%u] OUT OF MEMORY\n", __FILE__, __LINE__); _exit(EXIT_FAILURE); }
42 #define MPRINT1 if (debug_lvl) printf
43 #define CONTROL_MAGIC 0xabcd6809
71 fprintf(stderr,
"usage: control_test [OPTS]\n");
72 fprintf(stderr,
" -m <messages> Send number of messages.\n");
73 fprintf(stderr,
" -x Debugging mode.\n");
101 MPRINT1(
"Master waiting for events.\n");
103 num_events = kevent(
kq, NULL, 0, &kev, 1, NULL);
104 if (num_events < 0) {
105 fprintf(stderr,
"Failed reading kevent: %s\n",
fr_syserror(errno));
109 MPRINT1(
"Master draining the control plane.\n");
115 if (data_size == 0)
goto wait_for_events;
118 fprintf(stderr,
"Failed reading control message\n");
148 MPRINT1(
"\tWorker started.\n");
158 MPRINT1(
"\tWorker retrying message %zu\n", i);
163 MPRINT1(
"\tWorker sent message %zu\n", i);
166 MPRINT1(
"\tWorker exiting.\n");
175 int main(
int argc,
char *argv[])
184 while ((c = getopt(argc, argv,
"hm:o:tx")) != -1)
switch (c) {
199 argc -= (optind - 1);
200 argv += (optind - 1);
211 fprintf(stderr,
"control_test: Failed to create control plane\n");
221 (void) pthread_attr_init(&attr);
222 (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
227 (void) pthread_join(master_id, NULL);
fr_atomic_queue_t * fr_atomic_queue_alloc(TALLOC_CTX *ctx, size_t size)
Create fixed-size atomic queue.
Structure to hold the atomic queue.
#define NEVER_RETURNS
Should be placed before the function return type.
#define FR_CONTROL_ID_CHANNEL
#define FR_CONTROL_MAX_SIZE
#define FR_CONTROL_MAX_MESSAGES
static fr_ring_buffer_t * rb
int main(int argc, char *argv[])
static fr_atomic_queue_t * aq
static void * control_worker(UNUSED void *arg)
request_t * request_alloc(UNUSED TALLOC_CTX *ctx, UNUSED request_init_args_t const *args)
static void * control_master(UNUSED void *arg)
static size_t max_messages
static fr_control_t * control
static NEVER_RETURNS void usage(void)
void request_verify(UNUSED char const *file, UNUSED int line, UNUSED request_t *request)
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
ssize_t fr_control_message_pop(fr_atomic_queue_t *aq, uint32_t *p_id, void *data, size_t data_size)
Pop control-plane message.
fr_control_t * fr_control_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_atomic_queue_t *aq)
Create a control-plane signaling path.
int fr_control_message_send(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size)
Send a control-plane message.
static TALLOC_CTX * autofree
Optional arguments for initialising requests.
fr_ring_buffer_t * fr_ring_buffer_create(TALLOC_CTX *ctx, size_t size)
Create a ring buffer.
static _Thread_local int worker_id
Internal ID of the current worker thread.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
int fr_time_start(void)
Initialize the local time.