From: Hugo Landau Date: Wed, 24 Apr 2024 09:53:54 +0000 (+0100) Subject: QUIC REACTOR: Integrate RIO NOTIFIER X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c83c00ebfe6a964729c186b2e51490b24a2ab8b5;p=thirdparty%2Fopenssl.git QUIC REACTOR: Integrate RIO NOTIFIER Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/24971) --- diff --git a/include/internal/quic_reactor.h b/include/internal/quic_reactor.h index a6fdb7d123a..95216766550 100644 --- a/include/internal/quic_reactor.h +++ b/include/internal/quic_reactor.h @@ -13,6 +13,7 @@ # include "internal/sockets.h" # include "internal/quic_predef.h" # include "internal/thread_arch.h" +# include "internal/rio_notifier.h" # include # 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 * ============================= diff --git a/ssl/quic/quic_engine.c b/ssl/quic/quic_engine.c index 25f8fa04255..fae9737f243 100644 --- a/ssl/quic/quic_engine.c +++ b/ssl/quic/quic_engine.c @@ -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; } diff --git a/ssl/quic/quic_reactor.c b/ssl/quic/quic_reactor.c index abb6b1f50ed..6d1f8bc5cf2 100644 --- a/ssl/quic/quic_reactor.c +++ b/ssl/quic/quic_reactor.c @@ -14,11 +14,12 @@ * 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 * =============================