From: Alan T. DeKok Date: Tue, 23 Jan 2024 12:33:51 +0000 (-0500) Subject: might as well cache cfg, too X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56422f5678aab70b408c64a080d486a8dfeddaa6;p=thirdparty%2Ffreeradius-server.git might as well cache cfg, too --- diff --git a/src/lib/bio/fd.h b/src/lib/bio/fd.h index ac4de1ac292..bb3c411a579 100644 --- a/src/lib/bio/fd.h +++ b/src/lib/bio/fd.h @@ -59,22 +59,6 @@ typedef enum { // updates #fr_bio_fd_packet_ctx_t on successful FD read. } fr_bio_fd_type_t; -/** Run-time status of the socket. - * - */ -typedef struct { - fr_socket_t socket; //!< as connected socket - - fr_bio_fd_type_t type; //!< type of the socket - - fr_bio_fd_state_t state; //!< connecting, open, closed, etc. - - bool read_blocked; //!< did we block on read? - bool write_blocked; //!< did we block on write? - bool eof; //!< are we at EOF? - -} fr_bio_fd_info_t; - /** Configuration for sockets * * Each piece of information is broken out into a separate field, so that the configuration file parser can @@ -106,6 +90,23 @@ typedef struct { bool async; //!< is it async } fr_bio_fd_config_t; +/** Run-time status of the socket. + * + */ +typedef struct { + fr_socket_t socket; //!< as connected socket + + fr_bio_fd_type_t type; //!< type of the socket + + fr_bio_fd_state_t state; //!< connecting, open, closed, etc. + + bool read_blocked; //!< did we block on read? + bool write_blocked; //!< did we block on write? + bool eof; //!< are we at EOF? + + 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)); int fr_bio_fd_close(fr_bio_t *bio) CC_HINT(nonnull); diff --git a/src/lib/bio/fd_open.c b/src/lib/bio/fd_open.c index a5af073418c..290a16ee77d 100644 --- a/src/lib/bio/fd_open.c +++ b/src/lib/bio/fd_open.c @@ -714,9 +714,12 @@ int fr_bio_fd_socket_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) fr_strerror_clear(); - my->info.socket = (fr_socket_t) {}; - - my->info.socket.type = cfg->socket_type; + my->info = (fr_bio_fd_info_t) { + .socket = { + .type = cfg->socket_type, + }, + .cfg = cfg, + }; if (!cfg->path) { my->info.socket.af = cfg->src_ipaddr.af; @@ -744,7 +747,6 @@ int fr_bio_fd_socket_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) my->info.socket.type = SOCK_STREAM; my->info.socket.unix.path = cfg->path; protocol = 0; - break; } /* @@ -763,8 +765,11 @@ int fr_bio_fd_socket_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) fr_strerror_printf("Failed opening setting O_NONBLOCK: %s", fr_syserror(errno)); fail: - my->info.socket.fd = -1; + my->info.socket = (fr_socket_t) { + .fd = -1, + }; my->info.state = FR_BIO_FD_STATE_CLOSED; + my->info.cfg = NULL; close(fd); return -1; } @@ -867,5 +872,6 @@ int fr_bio_fd_socket_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) if (fr_bio_fd_init_accept(my) < 0) goto fail; break; } + return 0; }