From 104f63543f29f291677f61ec9b3ecc66c0b4b39f Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 23 Mar 2021 12:45:42 -0300 Subject: [PATCH] Change MaybeGetLoop to a virtual member func Minor simplification. --- llarp/ev/ev.hpp | 13 +++++++++++++ llarp/ev/ev_libuv.cpp | 6 ++---- llarp/ev/ev_libuv.hpp | 4 ++-- llarp/quic/client.cpp | 2 +- llarp/service/endpoint.cpp | 3 ++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/llarp/ev/ev.hpp b/llarp/ev/ev.hpp index ea6ee9cfd..7e3d38740 100644 --- a/llarp/ev/ev.hpp +++ b/llarp/ev/ev.hpp @@ -11,6 +11,11 @@ #include #include +namespace uvw +{ + class Loop; +} + namespace llarp { struct SockAddr; @@ -214,6 +219,14 @@ namespace llarp // Returns true if called from within the event loop thread, false otherwise. virtual bool inEventLoop() const = 0; + + // Returns the uvw::Loop *if* this event loop is backed by a uvw event loop (i.e. the default), + // nullptr otherwise. (This base class default always returns nullptr). + virtual std::shared_ptr + MaybeGetUVWLoop() + { + return nullptr; + } }; using EventLoop_ptr = std::shared_ptr; diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index a00cc5848..13e63c180 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -13,11 +13,9 @@ namespace llarp::uv { std::shared_ptr - Loop::MaybeGetLoop(const EventLoop_ptr& ptr) + Loop::MaybeGetUVWLoop() { - if (auto* uv = dynamic_cast(ptr.get())) - return uv->m_Impl; - return nullptr; + return m_Impl; } class UVWakeup final : public EventLoopWakeup diff --git a/llarp/ev/ev_libuv.hpp b/llarp/ev/ev_libuv.hpp index 53c01ad8a..e03b52c93 100644 --- a/llarp/ev/ev_libuv.hpp +++ b/llarp/ev/ev_libuv.hpp @@ -71,8 +71,8 @@ namespace llarp::uv std::function PumpLL; - static std::shared_ptr - MaybeGetLoop(const EventLoop_ptr&); + std::shared_ptr + MaybeGetUVWLoop() override; bool inEventLoop() const override; diff --git a/llarp/quic/client.cpp b/llarp/quic/client.cpp index 933774591..0a255dd6c 100644 --- a/llarp/quic/client.cpp +++ b/llarp/quic/client.cpp @@ -11,7 +11,7 @@ namespace llarp::quic { Client::Client(service::ConvoTag tag, service::Endpoint* parent, uint16_t tunnel_port) - : Endpoint{parent, uv::Loop::MaybeGetLoop(parent->Loop())} + : Endpoint{parent, parent->Loop()->MaybeGetUVWLoop()} { // Our UDP socket is now set up, so now we initiate contact with the remote QUIC Address remote{std::move(tag)}; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 5df9ffa03..426e75b8b 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -83,7 +83,8 @@ namespace llarp m_StartupLNSMappings[name] = std::make_pair(range, auth); }); - auto loop = uv::Loop::MaybeGetLoop(Router()->loop()); + auto loop = Router()->loop()->MaybeGetUVWLoop(); + assert(loop); auto callback = [this, loop, ports = conf.m_quicServerPorts]( quic::Server& serv, quic::Stream& stream, uint16_t port) { if (ports.count(port) == 0)