]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
put connect data into its own struct
authorAlan T. DeKok <aland@freeradius.org>
Mon, 18 Nov 2024 16:40:25 +0000 (11:40 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 19 Nov 2024 11:59:22 +0000 (06:59 -0500)
src/lib/bio/fd.c
src/lib/bio/fd.h
src/lib/bio/fd_priv.h

index c35f9750c4cc15933027e7ee7cbbf817018598c4..d6f9c4c22cf427a884c8ea79d072daef00a090e8 100644 (file)
@@ -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;
 }
index 21fedadf3858accd3e67e76f921f591f4068d376..6bbdf83a60e69afb7d763968782d0266f7eacb92 100644 (file)
@@ -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)
index b839ff7b6a4bc94fd894da5a6012b47adac74c4f..00c981f26f5d220cc1dc39850df4289fb2af34a0 100644 (file)
@@ -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