From: Alan T. DeKok Date: Mon, 19 Aug 2024 14:39:02 +0000 (-0400) Subject: move "set open" to common function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9b6680aec6c85629423ba914c74b817e8db65da;p=thirdparty%2Ffreeradius-server.git move "set open" to common function --- diff --git a/src/lib/bio/fd.c b/src/lib/bio/fd.c index 7557e88ef96..c83ec2f1030 100644 --- a/src/lib/bio/fd.c +++ b/src/lib/bio/fd.c @@ -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); /* diff --git a/src/lib/bio/fd_open.c b/src/lib/bio/fd_open.c index 018f4922613..406e800fcf0 100644 --- a/src/lib/bio/fd_open.c +++ b/src/lib/bio/fd_open.c @@ -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.