From: Arran Cudbard-Bell Date: Tue, 20 Jun 2017 20:55:09 +0000 (-0400) Subject: Add callback to set event list in app_io X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a2afd0b84755f2c16163a2ae5ba3e04b7180ea0;p=thirdparty%2Ffreeradius-server.git Add callback to set event list in app_io --- diff --git a/src/lib/io/application.h b/src/lib/io/application.h index 26223335764..94ffa2f5518 100644 --- a/src/lib/io/application.h +++ b/src/lib/io/application.h @@ -37,6 +37,7 @@ typedef struct fr_schedule_t fr_schedule_t; typedef int (*fr_app_open_t)(void *instance, fr_schedule_t *sc, CONF_SECTION *cs); typedef int (*fr_app_instantiate_t)(void *instance, CONF_SECTION *cs); typedef int (*fr_app_bootstrap_t)( void *instance, CONF_SECTION *cs); + /** Set the next state executed by the request to be one of the application subtype's entry points * * @param[in] instance of the #fr_app_t. @@ -44,12 +45,9 @@ typedef int (*fr_app_bootstrap_t)( void *instance, CONF_SECTION *cs); */ typedef void (*fr_app_process_set_t)(void const *instance, REQUEST *request); -/** Allows submodules to receive uctx data (a structure provided by their parent) - * - * @param[in] instance of #fr_app_process_t or #fr_app_io_t. - * @param[in] uctx provided by caller. +/** Called by the network thread to pass an event list for the module to use for timer events */ -typedef void (*fr_app_set_parent_inst_t)(void *instance, void *uctx); +typedef void (*fr_app_event_list_set_t)(fr_event_list_t *el); /** Describes a new application (protocol) * @@ -73,7 +71,6 @@ typedef struct fr_app_process_t { fr_app_bootstrap_t bootstrap; fr_app_instantiate_t instantiate; - fr_app_set_parent_inst_t set_parent_inst;//!< Allow the submodule to receive data from the main module. fr_io_process_t process; //!< Entry point into the protocol subtype's state machine. } fr_app_process_t; @@ -86,7 +83,8 @@ typedef struct fr_app_io_t { fr_app_bootstrap_t bootstrap; fr_app_instantiate_t instantiate; - fr_app_set_parent_inst_t set_parent_inst; //!< Allow the submodule to receive data from the main module. + fr_app_event_list_set_t event_list_set; //!< Called by the network thread to pass an event list + //!< for use by the app_io_t. size_t default_message_size; // Usually minimum message size diff --git a/src/lib/io/network.c b/src/lib/io/network.c index 56559c7ca3d..9cbdafb9fc2 100644 --- a/src/lib/io/network.c +++ b/src/lib/io/network.c @@ -455,10 +455,10 @@ static int _network_socket_free(fr_network_socket_t *s) */ static void fr_network_socket_callback(void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now) { - int fd; - fr_network_t *nr = ctx; - fr_network_socket_t *s; - fr_event_fd_handler_t write_fn, error_fn; + int fd; + fr_network_t *nr = ctx; + fr_network_socket_t *s; + fr_app_io_t const *app_io; rad_assert(data_size == sizeof(*s)); @@ -487,15 +487,18 @@ static void fr_network_socket_callback(void *ctx, void const *data, size_t data_ _exit(1); } - write_fn = error_fn = NULL; - - if (s->listen->app_io->flush) write_fn = fr_network_write; + app_io = s->listen->app_io; - if (s->listen->app_io->error) error_fn = fr_network_error; + if (app_io->event_list_set) app_io->event_list_set(nr->el); - fd = s->listen->app_io->fd(s->listen->app_io_instance); + rad_assert(app_io->fd); + fd = app_io->fd(s->listen->app_io_instance); - if (fr_event_fd_insert(nr->el, fd, fr_network_read, write_fn, error_fn, s) < 0) { + if (fr_event_fd_insert(nr->el, fd, + fr_network_read, + app_io->write ? fr_network_write : NULL, + app_io->error ? fr_network_error : NULL, + s) < 0) { fr_log(nr->log, L_ERR, "Failed adding new socket to event loop: %s", fr_strerror()); talloc_free(s); return;