From: Alan T. DeKok Date: Sat, 7 Jan 2023 13:58:35 +0000 (-0500) Subject: move commonly used functions to the trunk code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1829c0fb10002e41ec7a9f37c752b39c21d54da5;p=thirdparty%2Ffreeradius-server.git move commonly used functions to the trunk code There's no need to reproduce these in multiple client IO modules. --- diff --git a/src/lib/server/trunk.c b/src/lib/server/trunk.c index 1b9b3fffa0c..97ab792c662 100644 --- a/src/lib/server/trunk.c +++ b/src/lib/server/trunk.c @@ -3872,6 +3872,41 @@ void fr_trunk_connection_signal_reconnect(fr_trunk_connection_t *tconn, fr_conne fr_connection_signal_reconnect(tconn->pub.conn, reason); } +/** Standard I/O read function + * + * Underlying FD in now readable, so call the trunk to read any pending requests + * from this connection. + * + * @param[in] el The event list signalling. + * @param[in] fd that's now readable. + * @param[in] flags describing the read event. + * @param[in] uctx The trunk connection handle (tconn). + */ +void fr_trunk_connection_callback_readable(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx) +{ + fr_trunk_connection_t *tconn = talloc_get_type_abort(uctx, fr_trunk_connection_t); + + fr_trunk_connection_signal_readable(tconn); +} + +/** Standard I/O write function + * + * Underlying FD is now writable, so call the trunk to write any pending requests + * to this connection. + * + * @param[in] el The event list signalling. + * @param[in] fd that's now writable. + * @param[in] flags describing the write event. + * @param[in] uctx The trunk connection handle (tcon). + */ +void fr_trunk_connection_callback_writable(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx) +{ + fr_trunk_connection_t *tconn = talloc_get_type_abort(uctx, fr_trunk_connection_t); + + fr_trunk_connection_signal_writable(tconn); +} + + /** Returns true if the trunk connection is in one of the specified states * * @param[in] tconn To check state for. diff --git a/src/lib/server/trunk.h b/src/lib/server/trunk.h index 575a00c8fde..8ca9df92f05 100644 --- a/src/lib/server/trunk.h +++ b/src/lib/server/trunk.h @@ -846,6 +846,14 @@ void fr_trunk_connection_signal_reconnect(fr_trunk_connection_t *tconn, fr_conn bool fr_trunk_connection_in_state(fr_trunk_connection_t *tconn, int state); /** @} */ +/** @name Connection Callbacks + * @{ + */ +void fr_trunk_connection_callback_writable(fr_event_list_t *el, int fd, int flags, void *uctx); + +void fr_trunk_connection_callback_readable(fr_event_list_t *el, int fd, int flags, void *uctx); +/** @} */ + /** @name Connection management * @{ */ diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 0ff4be86107..7b1b247d578 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -981,40 +981,6 @@ static void conn_discard(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, v } } -/** Standard I/O read function - * - * Underlying FD in now readable, so call the trunk to read any pending requests - * from this connection. - * - * @param[in] el The event list signalling. - * @param[in] fd that's now readable. - * @param[in] flags describing the read event. - * @param[in] uctx The trunk connection handle (tconn). - */ -static void conn_readable(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx) -{ - fr_trunk_connection_t *tconn = talloc_get_type_abort(uctx, fr_trunk_connection_t); - - fr_trunk_connection_signal_readable(tconn); -} - -/** Standard I/O write function - * - * Underlying FD is now writable, so call the trunk to write any pending requests - * to this connection. - * - * @param[in] el The event list signalling. - * @param[in] fd that's now writable. - * @param[in] flags describing the write event. - * @param[in] uctx The trunk connection handle (tcon). - */ -static void conn_writable(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx) -{ - fr_trunk_connection_t *tconn = talloc_get_type_abort(uctx, fr_trunk_connection_t); - - fr_trunk_connection_signal_writable(tconn); -} - /** Connection errored * * We were signalled by the event loop that a fatal error occurred on this connection. @@ -1057,16 +1023,16 @@ static void thread_conn_notify(fr_trunk_connection_t *tconn, fr_connection_t *co break; case FR_TRUNK_CONN_EVENT_READ: - read_fn = conn_readable; + read_fn = fr_trunk_connection_callback_readable; break; case FR_TRUNK_CONN_EVENT_WRITE: - write_fn = conn_writable; + write_fn = fr_trunk_connection_callback_writable; break; case FR_TRUNK_CONN_EVENT_BOTH: - read_fn = conn_readable; - write_fn = conn_writable; + read_fn = fr_trunk_connection_callback_readable; + write_fn = fr_trunk_connection_callback_writable; break; } @@ -1109,7 +1075,7 @@ static void thread_conn_notify_replicate(fr_trunk_connection_t *tconn, fr_connec case FR_TRUNK_CONN_EVENT_BOTH: case FR_TRUNK_CONN_EVENT_WRITE: read_fn = conn_discard; - write_fn = conn_writable; + write_fn = fr_trunk_connection_callback_writable; break; }