Change MaybeGetLoop to a virtual member func

Minor simplification.
This commit is contained in:
Jason Rhinelander 2021-03-23 12:45:42 -03:00 committed by Jeff Becker
parent a1a1b2e2bc
commit 104f63543f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
5 changed files with 20 additions and 8 deletions

View File

@ -11,6 +11,11 @@
#include <future>
#include <utility>
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<uvw::Loop>
MaybeGetUVWLoop()
{
return nullptr;
}
};
using EventLoop_ptr = std::shared_ptr<EventLoop>;

View File

@ -13,11 +13,9 @@
namespace llarp::uv
{
std::shared_ptr<uvw::Loop>
Loop::MaybeGetLoop(const EventLoop_ptr& ptr)
Loop::MaybeGetUVWLoop()
{
if (auto* uv = dynamic_cast<Loop*>(ptr.get()))
return uv->m_Impl;
return nullptr;
return m_Impl;
}
class UVWakeup final : public EventLoopWakeup

View File

@ -71,8 +71,8 @@ namespace llarp::uv
std::function<void(void)> PumpLL;
static std::shared_ptr<uvw::Loop>
MaybeGetLoop(const EventLoop_ptr&);
std::shared_ptr<uvw::Loop>
MaybeGetUVWLoop() override;
bool
inEventLoop() const override;

View File

@ -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)};

View File

@ -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)