]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add read / write pause / resume debounce functions
authorAlan T. DeKok <aland@freeradius.org>
Fri, 17 May 2024 14:27:29 +0000 (10:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 17 May 2024 14:44:01 +0000 (10:44 -0400)
src/lib/bio/libfreeradius-bio.mk
src/lib/bio/packet.c [new file with mode: 0644]
src/lib/bio/packet.h
src/protocols/radius/client.c

index 0c69b158c0420691fe33535c917cb0b87b15db20..08d11b098f03ac7238f38fe369661c9977579622 100644 (file)
@@ -9,6 +9,7 @@ SOURCES :=              \
        mem.c           \
        network.c       \
        null.c          \
+       packet.c        \
        pipe.c          \
        queue.c         \
        dedup.c         \
diff --git a/src/lib/bio/packet.c b/src/lib/bio/packet.c
new file mode 100644 (file)
index 0000000..d11f917
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ *   This program is is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or (at
+ *   your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * $Id$
+ * @file lib/bio/packet.c
+ * @brief BIO PACKET handlers
+ *
+ * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
+ */
+
+#include <freeradius-devel/bio/bio_priv.h>
+#include <freeradius-devel/bio/packet.h>
+
+/*
+ *     Debounce functions to get to the right callback.
+ */
+void fr_bio_packet_write_blocked(fr_bio_t *bio)
+{
+       fr_bio_packet_t *my = bio->uctx;
+
+       my->write_blocked = true;
+
+       my->cb.write_blocked(my);
+}
+
+void fr_bio_packet_write_resume(fr_bio_t *bio)
+{
+       fr_bio_packet_t *my = bio->uctx;
+
+       my->write_blocked = false;
+
+       my->cb.write_resume(my);
+}
+
+void fr_bio_packet_read_blocked(fr_bio_t *bio)
+{
+       fr_bio_packet_t *my = bio->uctx;
+
+       my->read_blocked = true;
+
+       my->cb.read_blocked(my);
+}
+
+void fr_bio_packet_read_resume(fr_bio_t *bio)
+{
+       fr_bio_packet_t *my = bio->uctx;
+
+       my->read_blocked = false;
+
+       my->cb.read_resume(my);
+}
+
index 3809d3aa59825e68f454e778838b7f237936c400..5654f40f616ff27f6303e11e7b3a60f2b6a508c7 100644 (file)
@@ -172,3 +172,8 @@ static inline CC_HINT(nonnull) int fr_bio_packet_write_flush(fr_bio_packet_t *my
         */
        return slen;
 }
+
+void   fr_bio_packet_write_blocked(fr_bio_t *bio);
+void   fr_bio_packet_write_resume(fr_bio_t *bio);
+void   fr_bio_packet_read_blocked(fr_bio_t *bio);
+void   fr_bio_packet_read_resume(fr_bio_t *bio);
index f48cb6cdcc4b78827d6fa997322861e38b3ecbf9..6952de568a543e8daef9fc06de0a30e5f6dacae1 100644 (file)
@@ -509,19 +509,7 @@ int fr_radius_client_bio_connect(fr_bio_packet_t *bio)
        return rcode;
 }
 
-/*
- *     Debounce functions to get to the right callback.
- */
-static void fr_bio_write_blocked(fr_bio_t *bio)
-{
-       fr_radius_client_fd_bio_t *my = bio->uctx;
-
-       my->common.write_blocked = true;
-
-       my->common.cb.write_blocked(&my->common);
-}
-
-static void fr_bio_write_resume(fr_bio_t *bio)
+static void fr_radius_client_bio_write_resume(fr_bio_t *bio)
 {
        fr_radius_client_fd_bio_t *my = bio->uctx;
 
@@ -535,24 +523,6 @@ static void fr_bio_write_resume(fr_bio_t *bio)
        my->common.cb.write_resume(&my->common);
 }
 
-static void fr_bio_read_blocked(fr_bio_t *bio)
-{
-       fr_radius_client_fd_bio_t *my = bio->uctx;
-
-       my->common.read_blocked = true;
-
-       my->common.cb.read_blocked(&my->common);
-}
-
-static void fr_bio_read_resume(fr_bio_t *bio)
-{
-       fr_radius_client_fd_bio_t *my = bio->uctx;
-
-       my->common.read_blocked = false;
-
-       my->common.cb.read_resume(&my->common);
-}
-
 int fr_radius_client_bio_cb_set(fr_bio_packet_t *bio, fr_bio_packet_cb_funcs_t const *cb)
 {
        fr_radius_client_fd_bio_t *my = talloc_get_type_abort(bio, fr_radius_client_fd_bio_t);
@@ -565,11 +535,12 @@ int fr_radius_client_bio_cb_set(fr_bio_packet_t *bio, fr_bio_packet_cb_funcs_t c
        fr_assert((cb->read_blocked != NULL) == (cb->read_resume != NULL));
 
 #undef SET
-#define SET(_x) if (cb->_x) bio_cb._x = fr_bio_ ## _x
+#define SET(_x) if (cb->_x) bio_cb._x = fr_bio_packet_ ## _x
 
        SET(write_blocked);
+       if (cb->write_resume) bio_cb.write_resume = fr_radius_client_bio_write_resume;
+
        SET(read_blocked);
-       SET(write_resume);
        SET(read_resume);
 
        return fr_bio_cb_set(my->fd, &bio_cb);