From: Alan T. DeKok Date: Mon, 20 May 2024 12:55:25 +0000 (-0400) Subject: glue in activate / shutdown to fd bio. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc31c614b9f7150f5625ae640419202fb833306c;p=thirdparty%2Ffreeradius-server.git glue in activate / shutdown to fd bio. 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. --- diff --git a/src/lib/bio/base.c b/src/lib/bio/base.c index c8bde51f4e..1bafbe9f63 100644 --- a/src/lib/bio/base.c +++ b/src/lib/bio/base.c @@ -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); diff --git a/src/lib/bio/fd.c b/src/lib/bio/fd.c index be6b166257..0d355caeec 100644 --- a/src/lib/bio/fd.c +++ b/src/lib/bio/fd.c @@ -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. */