]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
might as well cache cfg, too
authorAlan T. DeKok <aland@freeradius.org>
Tue, 23 Jan 2024 12:33:51 +0000 (07:33 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 23 Jan 2024 12:33:51 +0000 (07:33 -0500)
src/lib/bio/fd.h
src/lib/bio/fd_open.c

index ac4de1ac292a67a1af979c3dc99097472bd5017f..bb3c411a579f9b10c562654f2ad4864310fe37c1 100644 (file)
@@ -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);
index a5af073418ce8bbcc9490351a3dae81b38d2b55d..290a16ee77d7fe3dd0f7b5c4a261321f722bfbba 100644 (file)
@@ -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;
 }