extern "C" {
#endif
+/** An opaque file descriptor handle
+ */
typedef struct fr_event_fd_t fr_event_fd_t;
+
+/** An opaque event list handle
+ */
typedef struct fr_event_list_t fr_event_list_t;
+
+/** An opaque timer handle
+ */
typedef struct fr_event_timer_t fr_event_timer_t;
-typedef void (*fr_event_callback_t)(void *, struct timeval *now);
-typedef int (*fr_event_status_t)(void *status_ctx, struct timeval *);
+/** Called when a timer event fires
+ *
+ * @param[in] now The current time.
+ * @param[in] ctx User ctx passed to #fr_event_timer_insert.
+ */
+typedef void (*fr_event_callback_t)(struct timeval *now, void *ctx);
+
+/** Called after each event loop cycle
+ *
+ * Called before calling kqueue to put the thread in a sleeping state.
+ *
+ * @param[in] now The current time.
+ * @param[in] ctx User ctx passed to #fr_event_list_create.
+ */
+typedef int (*fr_event_status_t)(struct timeval *now, void *ctx);
+
+/** Called when an IO event occurs on a file descriptor
+ *
+ * @param[in] el Event list the file descriptor was inserted into.
+ * @param[in] sock That experienced the IO event.
+ * @param[in] ctx User ctx passed to #fr_event_fd_insert.
+ */
typedef void (*fr_event_fd_handler_t)(fr_event_list_t *el, int sock, void *ctx);
+
+/** Called when a user kevent occurs
+ *
+ * @param[in] kq that received the user kevent.
+ * @param[in] kev The kevent.
+ * @param[in] ctx User ctx passed to #fr_event_user_insert.
+ */
typedef void (*fr_event_user_handler_t)(int kq, struct kevent const *kev, void *ctx);
int fr_event_list_num_fds(fr_event_list_t *el);
void radius_event_free(void);
int radius_event_process(void);
void radius_update_listener(rad_listen_t *listener);
-void revive_home_server(void *ctx, struct timeval *now);
+void revive_home_server(struct timeval *now, void *ctx);
void mark_home_server_dead(home_server_t *home, struct timeval *when);
/* evaluate.c */
}
if (strcmp(argv[last], "alive") == 0) {
- revive_home_server(home, NULL);
+ revive_home_server(NULL, home);
} else if (strcmp(argv[last], "dead") == 0) {
struct timeval now;
*/
#define STATE_MACHINE_DECL(_x) static void _x(REQUEST *request, fr_state_action_t action)
-static void request_timer(void *ctx, struct timeval *now);
+static void request_timer(struct timeval *now, void *ctx);
/** Insert #REQUEST back into the event heap, to continue executing at a future time
*
/*
* Callback for ALL timer events related to the request.
*/
-static void request_timer(void *ctx, UNUSED struct timeval *now)
+static void request_timer(UNUSED struct timeval *now, void *ctx)
{
REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
#ifdef DEBUG_STATE_MACHINE
/*
* Timer function for all TCP sockets.
*/
-static void tcp_socket_timer(void *ctx, struct timeval *now)
+static void tcp_socket_timer(struct timeval *now, void *ctx)
{
rad_listen_t *listener = talloc_get_type_abort(ctx, rad_listen_t);
listen_socket_t *sock = listener->data;
* Called from start of zombie period, OR after control socket
* marks the home server dead.
*/
-static void ping_home_server(void *ctx, struct timeval *now)
+static void ping_home_server(struct timeval *now, void *ctx)
{
home_server_t *home = talloc_get_type_abort(ctx, home_server_t);
REQUEST *request;
buffer, sizeof(buffer)),
home->port, (int) response_window->tv_sec, (int) response_window->tv_usec);
- ping_home_server(home, now);
+ ping_home_server(now, home);
}
struct timeval now;
gettimeofday(&now, NULL);
- ping_home_server(home, &now);
+ ping_home_server(&now, home);
} else {
DEBUG("PING: Already pinging home server %s", home->log_name);
}
}
-void revive_home_server(void *ctx, UNUSED struct timeval *now)
+void revive_home_server(UNUSED struct timeval *now, void *ctx)
{
home_server_t *home = talloc_get_type_abort(ctx, home_server_t);
char buffer[INET6_ADDRSTRLEN];
}
-static int event_status(UNUSED void *ctx, struct timeval *wake)
+static int event_status(struct timeval *wake, UNUSED void *ctx)
{
if (rad_debug_lvl == 0) {
if (just_started) {
* Emit a systemd watchdog notification and reschedule the event.
*/
#ifdef HAVE_SYSTEMD_WATCHDOG
-static void sd_watchdog_event(void *ctx)
+static void sd_watchdog_event(struct timeval *now, void *ctx)
{
struct timeval when;
fr_event_list_time(&when, el);
tv_add(&when, sd_watchdog_interval / 2);
- if (!fr_event_timer_insert(el, (fr_event_callback_t) sd_watchdog_event, ctx, &when, ctx)) {
+ if (!fr_event_timer_insert(el, sd_watchdog_event, ctx, &when, ctx)) {
rad_panic("Failed to insert watchdog event");
}
}
/** Process stats for a single interval
*
*/
-static void rs_stats_process(void *ctx, struct timeval *now)
+static void rs_stats_process(struct timeval *now, void *ctx)
{
size_t i;
size_t rs_codes_len = (sizeof(rs_useful_codes) / sizeof(*rs_useful_codes));
talloc_free(request);
}
-static void _rs_event(void *ctx, UNUSED struct timeval *now)
+static void _rs_event(UNUSED struct timeval *now, void *ctx)
{
rs_request_t *request = talloc_get_type_abort(ctx, rs_request_t);
request->event = NULL;
original->packet->timestamp = header->ts;
rs_tv_add_ms(&header->ts, conf->stats.timeout, &original->when);
if (fr_event_timer_insert(event->list, _rs_event, original,
- &original->when, &original->event) < 0) {
+ &original->when, &original->event) < 0) {
REDEBUG("Failed inserting new event");
talloc_free(original);
}
}
-static int _rs_event_status(UNUSED void *ctx, struct timeval *wake)
+static int _rs_event_status(struct timeval *wake, UNUSED void *ctx)
{
if (wake && ((wake->tv_sec != 0) || (wake->tv_usec >= 100000))) {
DEBUG2("Waking up in %d.%01u seconds.", (int) wake->tv_sec, (unsigned int) wake->tv_usec / 100000);
/** Re-open the collectd socket
*
*/
-static void rs_collectd_reopen(void *ctx, struct timeval *now)
+static void rs_collectd_reopen(struct timeval *now, void *ctx)
{
fr_event_list_t *list = ctx;
static fr_event_timer_t *event;
/*
* Enforce max_request_time.
*/
-static void max_request_time_hook(void *ctx, UNUSED struct timeval *now)
+static void max_request_time_hook(UNUSED struct timeval *now, void *ctx)
{
REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
#ifdef DEBUG_STATE_MACHINE
request->el = el;
if (fr_event_timer_insert(request->el, max_request_time_hook,
- request, &when, &request->ev) < 0) {
+ request, &when, &request->ev) < 0) {
REDEBUG("Failed inserting max_request_time");
}
} while (request != NULL);
/** Call the callback registered for a timeout event
*
- * @param[in] ctx unlang_event_t structure holding callbacks.
* @param[in] now The current time, as held by the event_list.
+ * @param[in] ctx unlang_event_t structure holding callbacks.
+ *
*/
-static void unlang_event_timeout_handler(void *ctx, struct timeval *now)
+static void unlang_event_timeout_handler(struct timeval *now, void *ctx)
{
#ifndef NDEBUG
unlang_event_t *ev = talloc_get_type_abort(ctx, unlang_event_t);
return RLM_MODULE_YIELD;
}
-static void unlang_timer_hook(void *ctx, UNUSED struct timeval *now)
+static void unlang_timer_hook(UNUSED struct timeval *now, void *ctx)
{
REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
#ifdef DEBUG_STATE_MACHINE
static int bfd_start_packets(bfd_state_t *session);
static int bfd_start_control(bfd_state_t *session);
static int bfd_stop_control(bfd_state_t *session);
-static void bfd_detection_timeout(void *ctx, struct timeval *now);
+static void bfd_detection_timeout(struct timeval *now, void *ctx);
static int bfd_process(bfd_state_t *session, bfd_packet_t *bfd);
static fr_event_list_t *el = NULL; /* don't ask */
/*
* Send a packet.
*/
-static void bfd_send_packet(void *ctx, UNUSED struct timeval *now)
+static void bfd_send_packet(UNUSED struct timeval *now, void *ctx)
{
bfd_state_t *session = ctx;
bfd_packet_t bfd;
}
-static void bfd_detection_timeout(void *ctx, struct timeval *now)
+static void bfd_detection_timeout(struct timeval *now, void *ctx)
{
bfd_state_t *session = ctx;
* @param[in] ctx the worker
* @param[in] wake the time when the event loop will wake up.
*/
-static int fr_worker_idle(void *ctx, struct timeval *wake)
+static int fr_worker_idle(struct timeval *wake, void *ctx)
{
bool found = false;
fr_worker_t *worker = ctx;