From: Alan T. DeKok Date: Mon, 21 Nov 2016 19:46:04 +0000 (-0500) Subject: event_status now can return 1 for "check events, but don't wait" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fa4d0ee68f9c83a77c3aa9a87acb9585ff62894;p=thirdparty%2Ffreeradius-server.git event_status now can return 1 for "check events, but don't wait" --- diff --git a/src/include/event.h b/src/include/event.h index 39dcaacdc6a..6f33aac12c2 100644 --- a/src/include/event.h +++ b/src/include/event.h @@ -35,7 +35,7 @@ typedef struct fr_event_list_t fr_event_list_t; typedef struct fr_event_timer_t fr_event_timer_t; typedef void (*fr_event_callback_t)(void *, struct timeval *now); -typedef void (*fr_event_status_t)(void *status_ctx, struct timeval *); +typedef int (*fr_event_status_t)(void *status_ctx, struct timeval *); typedef void (*fr_event_fd_handler_t)(fr_event_list_t *el, int sock, void *ctx); int fr_event_list_num_fds(fr_event_list_t *el); diff --git a/src/lib/event.c b/src/lib/event.c index 7024d2cc873..d71a650a767 100644 --- a/src/lib/event.c +++ b/src/lib/event.c @@ -516,9 +516,17 @@ int fr_event_corral(fr_event_list_t *el, bool wait) } /* - * Run the status callback + * Run the status callback. It may tell us that the + * application has more work to do, in which case we + * re-set the timeout to be instant. */ - if (el->status) el->status(el->status_ctx, wake); + if (el->status) { + if (el->status(el->status_ctx, wake) > 0) { + wake = &when; + when.tv_sec = 0; + when.tv_usec = 0; + } + } if (wake) { ts_wake = &ts_when; diff --git a/src/main/process.c b/src/main/process.c index caf9ac6cfc6..a641b70af3d 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -4773,24 +4773,26 @@ static void event_socket_handler(NDEBUG_UNUSED fr_event_list_t *xel, UNUSED int } -static void event_status(UNUSED void *ctx, struct timeval *wake) +static int event_status(UNUSED void *ctx, struct timeval *wake) { if (rad_debug_lvl == 0) { if (just_started) { INFO("Ready to process requests"); just_started = false; } - return; + return 0; } if (!wake) { - if (main_config.drop_requests) return; + if (main_config.drop_requests) return 0; INFO("Ready to process requests"); } else if ((wake->tv_sec != 0) || (wake->tv_usec >= 100000)) { DEBUG("Waking up in %d.%01u seconds.", (int) wake->tv_sec, (unsigned int) wake->tv_usec / 100000); } + + return 0; } static int event_new_fd(rad_listen_t *this) diff --git a/src/main/radsniff.c b/src/main/radsniff.c index 5ac74d44950..0260aab9ac4 100644 --- a/src/main/radsniff.c +++ b/src/main/radsniff.c @@ -1840,7 +1840,7 @@ static void rs_got_packet(fr_event_list_t *el, int fd, void *ctx) } } -static void _rs_event_status(UNUSED void *ctx, struct timeval *wake) +static int _rs_event_status(UNUSED void *ctx, struct timeval *wake) { 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); @@ -1849,6 +1849,8 @@ static void _rs_event_status(UNUSED void *ctx, struct timeval *wake) rs_time_print(timestr, sizeof(timestr), wake); } } + + return 0; } /** Compare requests using packet info and lists of attributes