]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC REACTOR: Integrate RIO NOTIFIER
authorHugo Landau <hlandau@openssl.org>
Wed, 24 Apr 2024 09:53:54 +0000 (10:53 +0100)
committerNeil Horman <nhorman@openssl.org>
Sat, 11 Jan 2025 21:02:29 +0000 (16:02 -0500)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24971)

include/internal/quic_reactor.h
ssl/quic/quic_engine.c
ssl/quic/quic_reactor.c

index a6fdb7d123a169d3f94324ddf6b1de49fd838326..952167665506bf4e6d4e8d4c335137cfa3f04a54 100644 (file)
@@ -13,6 +13,7 @@
 # include "internal/sockets.h"
 # include "internal/quic_predef.h"
 # include "internal/thread_arch.h"
+# include "internal/rio_notifier.h"
 # include <openssl/bio.h>
 
 # ifndef OPENSSL_NO_QUIC
@@ -99,6 +100,9 @@ struct quic_reactor_st {
     void (*tick_cb)(QUIC_TICK_RESULT *res, void *arg, uint32_t flags);
     void *tick_cb_arg;
 
+    /* Used to notify other threads. */
+    RIO_NOTIFIER notifier;
+
     /*
      * These are true if we would like to know when we can read or write from
      * the network respectively.
@@ -112,13 +116,22 @@ struct quic_reactor_st {
      */
     unsigned int can_poll_r : 1;
     unsigned int can_poll_w : 1;
+
+    /* 1 if notifier is present and initialised. */
+    unsigned int have_notifier : 1;
 };
 
-void ossl_quic_reactor_init(QUIC_REACTOR *rtor,
-                            void (*tick_cb)(QUIC_TICK_RESULT *res, void *arg,
-                                            uint32_t flags),
-                            void *tick_cb_arg,
-                            OSSL_TIME initial_tick_deadline);
+/* Create an OS notifier? */
+#define QUIC_REACTOR_FLAG_USE_NOTIFIER      (1U << 0)
+
+int ossl_quic_reactor_init(QUIC_REACTOR *rtor,
+                           void (*tick_cb)(QUIC_TICK_RESULT *res, void *arg,
+                                           uint32_t flags),
+                           void *tick_cb_arg,
+                           OSSL_TIME initial_tick_deadline,
+                           uint64_t flags);
+
+void ossl_quic_reactor_cleanup(QUIC_REACTOR *rtor);
 
 void ossl_quic_reactor_set_poll_r(QUIC_REACTOR *rtor,
                                   const BIO_POLL_DESCRIPTOR *r);
@@ -152,6 +165,8 @@ OSSL_TIME ossl_quic_reactor_get_tick_deadline(QUIC_REACTOR *rtor);
 
 int ossl_quic_reactor_tick(QUIC_REACTOR *rtor, uint32_t flags);
 
+RIO_NOTIFIER *ossl_quic_reactor_get0_notifier(QUIC_REACTOR *rtor);
+
 /*
  * Blocking I/O Adaptation Layer
  * =============================
index 25f8fa04255926416875c7385aba77b3c66f48a3..fae9737f243972241d9318e9e2601e8156beb7ee 100644 (file)
@@ -55,7 +55,7 @@ void ossl_quic_engine_free(QUIC_ENGINE *qeng)
 
 static int qeng_init(QUIC_ENGINE *qeng)
 {
-    ossl_quic_reactor_init(&qeng->rtor, qeng_tick, qeng, ossl_time_zero());
+    ossl_quic_reactor_init(&qeng->rtor, qeng_tick, qeng, ossl_time_zero(), 0);
     return 1;
 }
 
index abb6b1f50ed71d81c9cfe349a9a430b4f7867911..6d1f8bc5cf2908757446ed82604d862c95033c08 100644 (file)
  * Core I/O Reactor Framework
  * ==========================
  */
-void ossl_quic_reactor_init(QUIC_REACTOR *rtor,
-                            void (*tick_cb)(QUIC_TICK_RESULT *res, void *arg,
-                                            uint32_t flags),
-                            void *tick_cb_arg,
-                            OSSL_TIME initial_tick_deadline)
+int ossl_quic_reactor_init(QUIC_REACTOR *rtor,
+                           void (*tick_cb)(QUIC_TICK_RESULT *res, void *arg,
+                                           uint32_t flags),
+                           void *tick_cb_arg,
+                           OSSL_TIME initial_tick_deadline,
+                           uint64_t flags)
 {
     rtor->poll_r.type       = BIO_POLL_DESCRIPTOR_TYPE_NONE;
     rtor->poll_w.type       = BIO_POLL_DESCRIPTOR_TYPE_NONE;
@@ -30,6 +31,28 @@ void ossl_quic_reactor_init(QUIC_REACTOR *rtor,
 
     rtor->tick_cb           = tick_cb;
     rtor->tick_cb_arg       = tick_cb_arg;
+
+    if ((flags & QUIC_REACTOR_FLAG_USE_NOTIFIER) != 0) {
+        if (!ossl_rio_notifier_init(&rtor->notifier))
+            return 0;
+
+        rtor->have_notifier = 1;
+    } else {
+        rtor->have_notifier = 0;
+    }
+
+    return 1;
+}
+
+void ossl_quic_reactor_cleanup(QUIC_REACTOR *rtor)
+{
+    if (rtor == NULL)
+        return;
+
+    if (rtor->have_notifier) {
+        ossl_rio_notifier_cleanup(&rtor->notifier);
+        rtor->have_notifier = 0;
+    }
 }
 
 void ossl_quic_reactor_set_poll_r(QUIC_REACTOR *rtor, const BIO_POLL_DESCRIPTOR *r)
@@ -114,6 +137,11 @@ int ossl_quic_reactor_tick(QUIC_REACTOR *rtor, uint32_t flags)
     return 1;
 }
 
+RIO_NOTIFIER *ossl_quic_reactor_get0_notifier(QUIC_REACTOR *rtor)
+{
+    return rtor->have_notifier ? &rtor->notifier : NULL;
+}
+
 /*
  * Blocking I/O Adaptation Layer
  * =============================