]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
glue in activate / shutdown to fd bio.
authorAlan T. DeKok <aland@freeradius.org>
Mon, 20 May 2024 12:55:25 +0000 (08:55 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 21 May 2024 22:20:57 +0000 (18:20 -0400)
call activate() when the socket is ready, i.e. when it's
connected.

call shutdown() when the socket is closed, in the destructor.

when fr_bio_shutdown() is called manually, it also mangles the
shutdown callback, so that the fd bio doesn't call it again in
its destructor.

src/lib/bio/base.c
src/lib/bio/fd.c

index c8bde51f4ea11720892cd9037f78cf4573e50b61..1bafbe9f6385ec5ffc3db86610b185cb09b46511 100644 (file)
@@ -171,9 +171,13 @@ int fr_bio_shutdown(fr_bio_t *bio)
 
                /*
                 *      Call user shutdown before the bio shutdown.
+                *
+                *      Then set it to NULL so that it doesn't get called again on talloc cleanups.
                 */
                if (my->cb.shutdown && ((rcode = my->cb.shutdown(last)) < 0)) return rcode;
 
+               my->cb.shutdown = NULL;
+
                last = fr_bio_prev(last);
        } while (last);
 
index be6b166257bc303d96cd3414134527e9ed7c3be8..0d355caeec577a522408dd13f4a5c379b7e8c479 100644 (file)
@@ -100,6 +100,8 @@ static int fr_bio_fd_destructor(fr_bio_fd_t *my)
        fr_assert(!fr_bio_prev(&my->bio));
        fr_assert(!fr_bio_next(&my->bio));
 
+       if (my->cb.shutdown) my->cb.shutdown(&my->bio);
+
        return fr_bio_fd_close(&my->bio);
 }
 
@@ -844,6 +846,11 @@ int fr_bio_fd_init_common(fr_bio_fd_t *my)
        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);
+
        return 0;
 }
 
@@ -1110,8 +1117,6 @@ int fr_bio_fd_connect(fr_bio_t *bio)
                return fr_bio_error(IO);
        }
 
-       my->info.state = FR_BIO_FD_STATE_OPEN;
-
        /*
         *      The socket is connected, so initialize the normal IO handlers.
         */