]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
remove callbacks from fd_alloc()
authorAlan T. DeKok <aland@freeradius.org>
Tue, 14 May 2024 20:46:33 +0000 (16:46 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 14 May 2024 20:50:23 +0000 (16:50 -0400)
the caller can set it themselves, and it looks like every bio
may need to set the callbacks

and move the "set callback" code to a common bio function.

It's a bit more work for the caller when it's needed, but it's
much less work when it's not needed.

src/lib/bio/base.c
src/lib/bio/base.h
src/lib/bio/fd.c
src/lib/bio/fd.h
src/listen/control/proto_control_unix.c
src/protocols/radius/client.c

index 5dd95f1053bc436ea55b867bf4acf2efa5958108..c8bde51f4ea11720892cd9037f78cf4573e50b61 100644 (file)
@@ -222,3 +222,14 @@ char const *fr_bio_strerror(ssize_t error)
                return "<unknown>";
        }
 }
+
+int fr_bio_cb_set(fr_bio_t *bio, fr_bio_cb_funcs_t const *cb)
+{
+       fr_bio_common_t *my = (fr_bio_common_t *) bio;
+
+       if (!cb) cb = &(fr_bio_cb_funcs_t) { };
+
+       my->cb = *cb;
+
+       return 0;
+}
index 93f4d6861e7ccc927935412466a763cdfdcb0126..f62e69cc76b765ed2652ddc28640a9bcfbccbc34 100644 (file)
@@ -194,3 +194,5 @@ int fr_bio_shutdown(fr_bio_t *bio) CC_HINT(nonnull);
 int    fr_bio_free(fr_bio_t *bio) CC_HINT(nonnull);
 
 char const *fr_bio_strerror(ssize_t error);
+
+int fr_bio_cb_set(fr_bio_t *bio, fr_bio_cb_funcs_t const *cb) CC_HINT(nonnull(1));
index ced826da51a87bff97d995358f44d49217f3f4a7..457a2f059f9c5e9cc10e2750dbb1198d9ba410b6 100644 (file)
@@ -965,21 +965,19 @@ int fr_bio_fd_init_accept(fr_bio_fd_t *my)
  *  If a read returns EOF, then the FD remains open until talloc_free(bio) or fr_bio_fd_close() is called.
  *
  *  @param ctx         the talloc ctx
- *  @param cb          callbacks
  *  @param cfg         structure holding configuration information
  *  @param offset      only for unconnected datagram sockets, where #fr_bio_fd_packet_ctx_t is stored
  *  @return
  *     - NULL on error, memory allocation failed
  *     - !NULL the bio
  */
-fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_bio_fd_config_t const *cfg, size_t offset)
+fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_fd_config_t const *cfg, size_t offset)
 {
        fr_bio_fd_t *my;
 
        my = talloc_zero(ctx, fr_bio_fd_t);
        if (!my) return NULL;
 
-       if (cb) my->cb = *cb;
        my->max_tries = 4;
        my->offset = offset;
 
index 7c695251c409536b2789d34acdc02b71e13d741d..f90466b14e759f086c2f74f38fc66f10ba498996 100644 (file)
@@ -118,7 +118,7 @@ typedef struct {
        fr_bio_fd_config_t const *cfg;  //!< so we know what was asked, vs what was granted.
 } fr_bio_fd_info_t;
 
-fr_bio_t       *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_bio_fd_config_t const *cfg, size_t offset) CC_HINT(nonnull(1));
+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);
 
index ee6f52478ceb41e68760eb6b89a484633995388b..54f7aceaf0ea7a07f8c772506cf75751b9f7c0b4 100644 (file)
@@ -407,7 +407,7 @@ static int mod_open(fr_listen_t *li)
                .async = true,
        };
 
-       thread->fd_bio = fr_bio_fd_alloc(thread, NULL, &cfg, 0);
+       thread->fd_bio = fr_bio_fd_alloc(thread, &cfg, 0);
        if (!thread->fd_bio) {
                PERROR("Failed allocating UNIX path %s", inst->filename);
                return -1;
index 53cdb77345daefaba49c20b121cbc266a1f47189..ae32691e1d932d04a4ef0c22e06e89a11f73f654 100644 (file)
@@ -78,7 +78,7 @@ fr_radius_client_fd_bio_t *fr_radius_client_fd_bio_alloc(TALLOC_CTX *ctx, size_t
                if (!my->codes[i]) goto fail;
        }
 
-       my->fd = fr_bio_fd_alloc(my, NULL, fd_cfg, 0);
+       my->fd = fr_bio_fd_alloc(my, fd_cfg, 0);
        if (!my->fd) {
        fail:
                talloc_free(my);