From: Alan T. DeKok Date: Mon, 18 Nov 2024 16:40:25 +0000 (-0500) Subject: put connect data into its own struct X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b77767add1a37466a9bfc9f5868f231ee60980cb;p=thirdparty%2Ffreeradius-server.git put connect data into its own struct --- diff --git a/src/lib/bio/fd.c b/src/lib/bio/fd.c index c35f9750c4c..d6f9c4c22cf 100644 --- a/src/lib/bio/fd.c +++ b/src/lib/bio/fd.c @@ -102,14 +102,14 @@ static int fr_bio_fd_destructor(fr_bio_fd_t *my) if (!my->info.eof && my->cb.eof) my->cb.eof(&my->bio); - if (my->connect_ev) { - talloc_const_free(my->connect_ev); - my->connect_ev = NULL; + if (my->connect.ev) { + talloc_const_free(my->connect.ev); + my->connect.ev = NULL; } - if (my->connect_el) { - (void) fr_event_fd_delete(my->connect_el, my->info.socket.fd, FR_EVENT_FILTER_IO); - my->connect_el = NULL; + if (my->connect.el) { + (void) fr_event_fd_delete(my->connect.el, my->info.socket.fd, FR_EVENT_FILTER_IO); + my->connect.el = NULL; } if (my->cb.shutdown) my->cb.shutdown(&my->bio); @@ -1123,8 +1123,10 @@ static void fr_bio_fd_el_error(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED { fr_bio_fd_t *my = talloc_get_type_abort(uctx, fr_bio_fd_t); - if (my->connect_error) { - my->connect_error(&my->bio, fd_errno); + my->info.connect_errno = fd_errno; + + if (my->connect.error) { + my->connect.error(&my->bio); } fr_bio_shutdown(&my->bio); @@ -1140,8 +1142,8 @@ static void fr_bio_fd_el_connect(NDEBUG_UNUSED fr_event_list_t *el, NDEBUG_UNUSE fr_assert(my->info.type == FR_BIO_FD_CONNECTED); fr_assert(my->info.state == FR_BIO_FD_STATE_CONNECTING); - fr_assert(my->connect_el == el); /* and not NULL */ - fr_assert(my->connect_success != NULL); + fr_assert(my->connect.el == el); /* and not NULL */ + fr_assert(my->connect.success != NULL); fr_assert(my->info.socket.fd == fd); #ifndef NDEBUG @@ -1188,18 +1190,18 @@ static void fr_bio_fd_el_connect(NDEBUG_UNUSED fr_event_list_t *el, NDEBUG_UNUSE */ if (fr_bio_fd_try_connect(my) < 0) return; - fr_assert(my->connect_success); + fr_assert(my->connect.success); - if (my->connect_ev) { - talloc_const_free(my->connect_ev); - my->connect_ev = NULL; + if (my->connect.ev) { + talloc_const_free(my->connect.ev); + my->connect.ev = NULL; } - my->connect_el = NULL; + my->connect.el = NULL; /* * This function MUST change the read/write/error callbacks for the FD. */ - my->connect_success(&my->bio); + my->connect.success(&my->bio); } /** We have a timeout on the conenction @@ -1209,9 +1211,9 @@ static void fr_bio_fd_el_timeout(UNUSED fr_event_list_t *el, UNUSED fr_time_t no { fr_bio_fd_t *my = talloc_get_type_abort(uctx, fr_bio_fd_t); - fr_assert(my->connect_timeout); + fr_assert(my->connect.timeout); - my->connect_timeout(&my->bio); + my->connect.timeout(&my->bio); fr_bio_shutdown(&my->bio); } @@ -1234,7 +1236,7 @@ static void fr_bio_fd_el_timeout(UNUSED fr_event_list_t *el, UNUSED fr_time_t no * - 1 for "we are now connected". */ int fr_bio_fd_connect_full(fr_bio_t *bio, fr_event_list_t *el, fr_bio_callback_t connected_cb, - fr_bio_fd_connect_error_t error_cb, + fr_bio_callback_t error_cb, fr_time_delta_t *timeout, fr_bio_callback_t timeout_cb) { fr_bio_fd_t *my = talloc_get_type_abort(bio, fr_bio_fd_t); @@ -1293,15 +1295,15 @@ int fr_bio_fd_connect_full(fr_bio_t *bio, fr_event_list_t *el, fr_bio_callback_t /* * Set the callbacks to run when something happens. */ - my->connect_success = connected_cb; - my->connect_error = error_cb; - my->connect_timeout = timeout_cb; + my->connect.success = connected_cb; + my->connect.error = error_cb; + my->connect.timeout = timeout_cb; /* * Set the timeout callback if asked. */ if (timeout_cb) { - if (fr_event_timer_in(my, el, &my->connect_ev, *timeout, fr_bio_fd_el_timeout, my) < 0) { + if (fr_event_timer_in(my, el, &my->connect.ev, *timeout, fr_bio_fd_el_timeout, my) < 0) { goto error; } } @@ -1313,7 +1315,7 @@ int fr_bio_fd_connect_full(fr_bio_t *bio, fr_event_list_t *el, fr_bio_callback_t fr_bio_fd_el_connect, fr_bio_fd_el_error, my) < 0) { goto error; } - my->connect_el = el; + my->connect.el = el; return 0; } diff --git a/src/lib/bio/fd.h b/src/lib/bio/fd.h index 21fedadf385..6bbdf83a60e 100644 --- a/src/lib/bio/fd.h +++ b/src/lib/bio/fd.h @@ -117,17 +117,17 @@ typedef struct { bool write_blocked; //!< did we block on write? bool eof; //!< are we at EOF? + int connect_errno; //!< from connect() or other APIs + fr_bio_fd_config_t const *cfg; //!< so we know what was asked, vs what was granted. } fr_bio_fd_info_t; -typedef void (*fr_bio_fd_connect_error_t)(fr_bio_t *bio, int fd_errno); - fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_fd_config_t const *cfg, size_t offset) CC_HINT(nonnull(1)); int fr_bio_fd_close(fr_bio_t *bio) CC_HINT(nonnull); int fr_bio_fd_connect_full(fr_bio_t *bio, fr_event_list_t *el, - fr_bio_callback_t connected_cb, fr_bio_fd_connect_error_t error_cb, + fr_bio_callback_t connected_cb, fr_bio_callback_t error_cb, fr_time_delta_t *timeout, fr_bio_callback_t timeout_cb) CC_HINT(nonnull(1)); #define fr_bio_fd_connect(_x) fr_bio_fd_connect_full(_x, NULL, NULL, NULL, NULL, NULL) diff --git a/src/lib/bio/fd_priv.h b/src/lib/bio/fd_priv.h index b839ff7b6a4..00c981f26f5 100644 --- a/src/lib/bio/fd_priv.h +++ b/src/lib/bio/fd_priv.h @@ -38,11 +38,13 @@ typedef struct fr_bio_fd_s { fr_bio_fd_info_t info; - fr_bio_callback_t connect_success; //!< for fr_bio_fd_connect() - fr_bio_fd_connect_error_t connect_error; //!< for fr_bio_fd_connect() - fr_bio_callback_t connect_timeout; //!< for fr_bio_fd_connect() - fr_event_list_t *connect_el; //!< for fr_bio_fd_connect() - fr_event_timer_t const *connect_ev; //!< for fr_bio_fd_connect() + struct { + fr_bio_callback_t success; //!< for fr_bio_fd_connect() + fr_bio_callback_t error; //!< for fr_bio_fd_connect() + fr_bio_callback_t timeout; //!< for fr_bio_fd_connect() + fr_event_list_t *el; //!< for fr_bio_fd_connect() + fr_event_timer_t const *ev; //!< for fr_bio_fd_connect() + } connect; int max_tries; //!< how many times we retry on EINTR size_t offset; //!< where #fr_bio_fd_packet_ctx_t is stored