From: Alan T. DeKok Date: Tue, 23 Jan 2024 13:04:17 +0000 (-0500) Subject: add cfg to alloc routine, too X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9df4659db2363a24941cc6384bec3793a4204889;p=thirdparty%2Ffreeradius-server.git add cfg to alloc routine, too --- diff --git a/src/lib/bio/fd.c b/src/lib/bio/fd.c index 8ca8c7bf9d2..49bb7be9ac7 100644 --- a/src/lib/bio/fd.c +++ b/src/lib/bio/fd.c @@ -917,15 +917,13 @@ int fr_bio_fd_init_accept(fr_bio_fd_t *my) * * @param ctx the talloc ctx * @param cb callbacks - * @param sock structure holding socket information - * src_ip is always *our* IP. dst_ip is always *their* IP. - * @param type type of the bio + * @param cfg structure holding configuration information * @param offset for 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_socket_t const *sock, fr_bio_fd_type_t type, size_t offset) +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_fd_t *my; @@ -936,27 +934,15 @@ fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_socket_t co my->max_tries = 4; my->offset = offset; - if (sock) { - my->info.type = type; - my->info.state = FR_BIO_FD_STATE_CLOSED; - - if ((my->info.socket.fd >= 0) && - (fr_bio_fd_init(&my->bio, sock) < 0)) { - talloc_free(my); - return NULL; - } - } else { + if (!cfg) { /* - * We can allocate a "place-holder" FD bio, and then later fill it in with - * fr_bio_fd_init(). - * - * @todo - maybe just use fr_bio_fd_open() all of the time? + * Add place-holder information. */ my->info = (fr_bio_fd_info_t) { .socket = { .af = AF_UNSPEC, }, - .type = type, + .type = FR_BIO_FD_UNCONNECTED, .read_blocked = true, .write_blocked = true, .eof = false, @@ -965,6 +951,13 @@ fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_socket_t co my->bio.read = fr_bio_eof_read; my->bio.write = fr_bio_null_write; + } else { + my->info.state = FR_BIO_FD_STATE_CLOSED; + + if (fr_bio_fd_socket_open(&my->bio, cfg) < 0) { + talloc_free(my); + return NULL; + } } talloc_set_destructor(my, fr_bio_fd_destructor); diff --git a/src/lib/bio/fd.h b/src/lib/bio/fd.h index bb3c411a579..933a0cb0f29 100644 --- a/src/lib/bio/fd.h +++ b/src/lib/bio/fd.h @@ -107,7 +107,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_socket_t const *sock, fr_bio_fd_type_t type, size_t offset) CC_HINT(nonnull(1)); +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)); int fr_bio_fd_close(fr_bio_t *bio) CC_HINT(nonnull);