]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move "set open" to common function
authorAlan T. DeKok <aland@freeradius.org>
Mon, 19 Aug 2024 14:39:02 +0000 (10:39 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 19 Aug 2024 14:39:02 +0000 (10:39 -0400)
src/lib/bio/fd.c
src/lib/bio/fd_open.c

index 7557e88ef96a365b87bd452dcc565c0b5ad3a8d0..c83ec2f10302227f2cfa5ffe37996a681cabc2ba 100644 (file)
@@ -640,6 +640,19 @@ int fr_bio_fd_socket_name(fr_bio_fd_t *my)
        return 0;
 }
 
+static void fr_bio_fd_set_open(fr_bio_fd_t *my)
+{
+       my->info.state = FR_BIO_FD_STATE_OPEN;
+       my->info.eof = false;
+       my->info.read_blocked = false;
+       my->info.write_blocked = false;
+
+       /*
+        *      Tell the caller that the socket is ready for application data.
+        */
+       if (my->cb.activate) my->cb.activate(&my->bio);
+}
+
 
 /** Try to connect().
  *
@@ -668,7 +681,7 @@ static ssize_t fr_bio_fd_try_connect(fr_bio_fd_t *my)
 
 retry:
         if (connect(my->info.socket.fd, (struct sockaddr *) &sockaddr, salen) == 0) {
-                my->info.state = FR_BIO_FD_STATE_OPEN;
+               fr_bio_fd_set_open(my);
 
                /*
                 *      The source IP may have changed, so get the new one.
@@ -717,15 +730,13 @@ fail:
         return fr_bio_error(IO);
 }
 
+
 /** Files are a special case of connected sockets.
  *
  */
 static int fr_bio_fd_init_file(fr_bio_fd_t *my)
 {
-       my->info.state = FR_BIO_FD_STATE_OPEN;
-       my->info.eof = false;
-       my->info.read_blocked = false;
-       my->info.write_blocked = false;
+       fr_bio_fd_set_open(my);
 
        /*
         *      Other flags may be O_CREAT, etc.
@@ -853,15 +864,7 @@ int fr_bio_fd_init_common(fr_bio_fd_t *my)
                return -1;
        }
 
-       my->info.state = FR_BIO_FD_STATE_OPEN;
-       my->info.eof = false;
-       my->info.read_blocked = false;
-       my->info.write_blocked = false;
-
-       /*
-        *      Tell the caller that the socket is ready for application data.
-        */
-       if (my->cb.activate) my->cb.activate(&my->bio);
+       fr_bio_fd_set_open(my);
 
        return 0;
 }
@@ -945,11 +948,6 @@ retry:
 
 int fr_bio_fd_init_accept(fr_bio_fd_t *my)
 {
-       my->info.state = FR_BIO_FD_STATE_OPEN;
-       my->info.eof = false;
-       my->info.read_blocked = true;
-       my->info.write_blocked = false; /* don't select() for write */
-
        my->bio.read = fr_bio_fd_read_accept;
        my->bio.write = fr_bio_null_write;
 
@@ -958,6 +956,8 @@ int fr_bio_fd_init_accept(fr_bio_fd_t *my)
                return -1;
        }
 
+       fr_bio_fd_set_open(my);
+
        return 0;
 }
 
@@ -1110,6 +1110,14 @@ int fr_bio_fd_connect(fr_bio_t *bio)
 
        if (my->info.state == FR_BIO_FD_STATE_OPEN) return 0;
 
+       /*
+        *      The caller may just call us without caring about the underlying bio.
+        */
+       if ((my->info.socket.af == AF_FILE_BIO) || (my->info.type == FR_BIO_FD_ACCEPT)) {
+               fr_bio_fd_set_open(my);
+               return 0;
+       }
+
        if (my->info.state != FR_BIO_FD_STATE_CONNECTING) return fr_bio_error(GENERIC);
 
        /*
index 018f4922613af5e709dc15c493f12aff60fbbf7d..406e800fcf0bc4c7cfefbcc4c05b461792e57f8e 100644 (file)
@@ -839,7 +839,7 @@ int fr_bio_fd_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg)
        /*
         *      Initialize the bio information before calling the various setup functions.
         */
-       my->info.state = (cfg->type == FR_BIO_FD_CONNECTED) ? FR_BIO_FD_STATE_CONNECTING : FR_BIO_FD_STATE_OPEN;
+       my->info.state = FR_BIO_FD_STATE_CONNECTING;
 
        /*
         *      Set the FD so that the subsequent calls can use it.