2022-07-28 16:07:38 +00:00
|
|
|
#include "libuv.hpp"
|
2021-03-02 02:06:20 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <thread>
|
|
|
|
#include <type_traits>
|
2022-07-28 16:07:38 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2022-08-18 14:31:39 +00:00
|
|
|
#include <llarp/util/exceptions.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/thread/queue.hpp>
|
2022-07-28 16:07:38 +00:00
|
|
|
#include <llarp/vpn/platform.hpp>
|
2019-06-02 21:17:05 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
#include <uvw.hpp>
|
2019-09-16 10:21:12 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
namespace llarp::uv
|
|
|
|
{
|
2021-03-12 13:50:21 +00:00
|
|
|
std::shared_ptr<uvw::Loop>
|
2021-03-23 15:45:42 +00:00
|
|
|
Loop::MaybeGetUVWLoop()
|
2021-03-12 13:50:21 +00:00
|
|
|
{
|
2021-03-23 15:45:42 +00:00
|
|
|
return m_Impl;
|
2021-03-12 13:50:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
class UVWakeup final : public EventLoopWakeup
|
2021-02-22 13:26:32 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
std::shared_ptr<uvw::AsyncHandle> async;
|
2021-02-22 13:26:32 +00:00
|
|
|
|
|
|
|
public:
|
2021-03-02 02:06:20 +00:00
|
|
|
UVWakeup(uvw::Loop& loop, std::function<void()> callback)
|
|
|
|
: async{loop.resource<uvw::AsyncHandle>()}
|
2021-02-22 13:26:32 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
async->on<uvw::AsyncEvent>([f = std::move(callback)](auto&, auto&) { f(); });
|
2021-02-22 13:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-02 02:06:20 +00:00
|
|
|
Trigger() override
|
2021-02-22 13:26:32 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
async->send();
|
2021-02-22 13:26:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
~UVWakeup() override
|
2021-02-22 13:26:32 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
async->close();
|
2021-02-22 13:26:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
class UVRepeater final : public EventLoopRepeater
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
std::shared_ptr<uvw::TimerHandle> timer;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
public:
|
|
|
|
UVRepeater(uvw::Loop& loop) : timer{loop.resource<uvw::TimerHandle>()}
|
|
|
|
{}
|
2019-09-05 17:39:09 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
void
|
|
|
|
start(llarp_time_t every, std::function<void()> task) override
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
timer->start(every, every);
|
|
|
|
timer->on<uvw::TimerEvent>([task = std::move(task)](auto&, auto&) { task(); });
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
~UVRepeater() override
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
timer->stop();
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
struct UDPHandle final : llarp::UDPHandle
|
2019-06-02 21:17:05 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
UDPHandle(uvw::Loop& loop, ReceiveFunc rf);
|
2019-06-02 21:17:05 +00:00
|
|
|
|
|
|
|
bool
|
2021-03-02 02:06:20 +00:00
|
|
|
listen(const SockAddr& addr) override;
|
2019-06-02 21:17:05 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
bool
|
|
|
|
send(const SockAddr& dest, const llarp_buffer_t& buf) override;
|
2019-06-02 21:17:05 +00:00
|
|
|
|
2022-04-07 20:44:23 +00:00
|
|
|
std::optional<SockAddr>
|
|
|
|
LocalAddr() const override
|
|
|
|
{
|
2023-05-20 22:18:40 +00:00
|
|
|
if (auto addr = handle->sock<uvw::IPv4>(); not addr.ip.empty())
|
|
|
|
return SockAddr{addr.ip, huint16_t{static_cast<uint16_t>(addr.port)}};
|
|
|
|
if (auto addr = handle->sock<uvw::IPv6>(); not addr.ip.empty())
|
|
|
|
return SockAddr{addr.ip, huint16_t{static_cast<uint16_t>(addr.port)}};
|
|
|
|
return std::nullopt;
|
2022-04-07 20:44:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 23:22:59 +00:00
|
|
|
std::optional<int>
|
|
|
|
file_descriptor() override
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
if (int fd = handle->fd(); fd >= 0)
|
|
|
|
return fd;
|
|
|
|
#endif
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:17:05 +00:00
|
|
|
void
|
2021-03-02 02:06:20 +00:00
|
|
|
close() override;
|
2019-06-02 21:37:29 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
~UDPHandle() override;
|
2019-06-02 21:17:05 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<uvw::UDPHandle> handle;
|
2019-06-02 21:17:05 +00:00
|
|
|
|
|
|
|
void
|
2021-03-02 02:06:20 +00:00
|
|
|
reset_handle(uvw::Loop& loop);
|
2019-06-02 21:17:05 +00:00
|
|
|
};
|
2019-11-23 04:47:08 +00:00
|
|
|
|
2020-05-15 12:36:38 +00:00
|
|
|
void
|
|
|
|
Loop::FlushLogic()
|
|
|
|
{
|
2020-10-21 13:06:43 +00:00
|
|
|
llarp::LogTrace("Loop::FlushLogic() start");
|
2020-05-15 12:36:38 +00:00
|
|
|
while (not m_LogicCalls.empty())
|
|
|
|
{
|
2020-05-26 18:04:43 +00:00
|
|
|
auto f = m_LogicCalls.popFront();
|
2020-05-15 12:36:38 +00:00
|
|
|
f();
|
|
|
|
}
|
2020-10-21 13:06:43 +00:00
|
|
|
llarp::LogTrace("Loop::FlushLogic() end");
|
2020-05-15 12:36:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
void
|
|
|
|
Loop::tick_event_loop()
|
2019-11-23 04:47:08 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
llarp::LogTrace("ticking event loop.");
|
|
|
|
FlushLogic();
|
2019-11-23 04:47:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 13:25:14 +00:00
|
|
|
Loop::Loop(size_t queue_size) : llarp::EventLoop{}, m_LogicCalls{queue_size}
|
2019-06-02 21:17:05 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
if (!(m_Impl = uvw::Loop::create()))
|
|
|
|
throw std::runtime_error{"Failed to construct libuv loop"};
|
2019-11-28 02:35:59 +00:00
|
|
|
|
|
|
|
#ifdef LOKINET_DEBUG
|
2020-04-07 18:38:56 +00:00
|
|
|
last_time = 0;
|
2019-11-28 02:35:59 +00:00
|
|
|
loop_run_count = 0;
|
|
|
|
#endif
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2019-12-11 21:18:47 +00:00
|
|
|
#endif
|
2021-03-02 02:06:20 +00:00
|
|
|
|
2019-06-02 21:17:05 +00:00
|
|
|
m_Run.store(true);
|
2019-11-23 04:47:08 +00:00
|
|
|
m_nextID.store(0);
|
2021-03-02 02:06:20 +00:00
|
|
|
if (!(m_WakeUp = m_Impl->resource<uvw::AsyncHandle>()))
|
|
|
|
throw std::runtime_error{"Failed to create libuv async"};
|
|
|
|
m_WakeUp->on<uvw::AsyncEvent>([this](const auto&, auto&) { tick_event_loop(); });
|
2019-06-02 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Loop::running() const
|
|
|
|
{
|
|
|
|
return m_Run.load();
|
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
void
|
2021-03-02 07:02:59 +00:00
|
|
|
Loop::run()
|
2020-05-15 12:36:38 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
llarp::LogTrace("Loop::run_loop()");
|
2020-06-16 11:28:20 +00:00
|
|
|
m_EventLoopThreadID = std::this_thread::get_id();
|
2021-03-02 02:06:20 +00:00
|
|
|
m_Impl->run();
|
2021-03-02 07:02:59 +00:00
|
|
|
m_Impl->close();
|
|
|
|
m_Impl.reset();
|
|
|
|
llarp::LogInfo("we have stopped");
|
2020-05-15 12:36:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 18:59:39 +00:00
|
|
|
void
|
|
|
|
Loop::wakeup()
|
|
|
|
{
|
|
|
|
m_WakeUp->send();
|
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
std::shared_ptr<llarp::UDPHandle>
|
2021-03-02 20:44:30 +00:00
|
|
|
Loop::make_udp(UDPReceiveFunc on_recv)
|
2019-11-23 04:47:08 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
return std::static_pointer_cast<llarp::UDPHandle>(
|
|
|
|
std::make_shared<llarp::uv::UDPHandle>(*m_Impl, std::move(on_recv)));
|
2019-11-23 04:47:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 15:23:38 +00:00
|
|
|
static void
|
|
|
|
setup_oneshot_timer(uvw::Loop& loop, llarp_time_t delay, std::function<void()> callback)
|
|
|
|
{
|
2021-03-02 07:02:59 +00:00
|
|
|
auto timer = loop.resource<uvw::TimerHandle>();
|
|
|
|
timer->on<uvw::TimerEvent>([f = std::move(callback)](const auto&, auto& timer) {
|
|
|
|
f();
|
|
|
|
timer.stop();
|
|
|
|
timer.close();
|
|
|
|
});
|
|
|
|
timer->start(delay, 0ms);
|
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
void
|
2021-03-02 07:02:59 +00:00
|
|
|
Loop::call_later(llarp_time_t delay_ms, std::function<void(void)> callback)
|
2019-11-23 04:47:08 +00:00
|
|
|
{
|
2020-10-21 13:06:43 +00:00
|
|
|
llarp::LogTrace("Loop::call_after_delay()");
|
2020-01-23 12:59:51 +00:00
|
|
|
#ifdef TESTNET_SPEED
|
|
|
|
delay_ms *= TESTNET_SPEED;
|
|
|
|
#endif
|
2021-03-02 07:02:59 +00:00
|
|
|
|
|
|
|
if (inEventLoop())
|
|
|
|
setup_oneshot_timer(*m_Impl, delay_ms, std::move(callback));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
call_soon([this, f = std::move(callback), target_time = time_now() + delay_ms] {
|
2021-03-02 15:23:38 +00:00
|
|
|
// Recalculate delay because it may have taken some time to get ourselves into the logic
|
|
|
|
// thread
|
2021-03-02 07:02:59 +00:00
|
|
|
auto updated_delay = target_time - time_now();
|
|
|
|
if (updated_delay <= 0ms)
|
2021-03-02 15:23:38 +00:00
|
|
|
f(); // Timer already expired!
|
2021-03-02 07:02:59 +00:00
|
|
|
else
|
|
|
|
setup_oneshot_timer(*m_Impl, updated_delay, std::move(f));
|
|
|
|
});
|
|
|
|
}
|
2019-11-23 04:47:08 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 21:17:05 +00:00
|
|
|
void
|
|
|
|
Loop::stop()
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_Run)
|
2019-11-20 19:45:23 +00:00
|
|
|
{
|
2021-03-02 07:02:59 +00:00
|
|
|
if (not inEventLoop())
|
|
|
|
return call_soon([this] { stop(); });
|
|
|
|
|
2019-11-20 19:45:23 +00:00
|
|
|
llarp::LogInfo("stopping event loop");
|
2021-03-02 02:06:20 +00:00
|
|
|
m_Impl->walk([](auto&& handle) {
|
|
|
|
if constexpr (!std::is_pointer_v<std::remove_reference_t<decltype(handle)>>)
|
|
|
|
handle.close();
|
|
|
|
});
|
|
|
|
llarp::LogDebug("Closed all handles, stopping the loop");
|
|
|
|
m_Impl->stop();
|
2019-06-20 18:28:26 +00:00
|
|
|
|
2021-03-02 07:02:59 +00:00
|
|
|
m_Run.store(false);
|
2019-06-02 21:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
Loop::add_ticker(std::function<void(void)> func)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
auto check = m_Impl->resource<uvw::CheckHandle>();
|
|
|
|
check->on<uvw::CheckEvent>([f = std::move(func)](auto&, auto&) { f(); });
|
|
|
|
check->start();
|
|
|
|
return true;
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 21:17:05 +00:00
|
|
|
bool
|
2021-01-11 23:13:22 +00:00
|
|
|
Loop::add_network_interface(
|
|
|
|
std::shared_ptr<llarp::vpn::NetworkInterface> netif,
|
|
|
|
std::function<void(llarp::net::IPPacket)> handler)
|
2019-06-02 21:17:05 +00:00
|
|
|
{
|
2021-07-29 20:40:25 +00:00
|
|
|
#ifdef __linux__
|
2021-03-02 02:06:20 +00:00
|
|
|
using event_t = uvw::PollEvent;
|
|
|
|
auto handle = m_Impl->resource<uvw::PollHandle>(netif->PollFD());
|
|
|
|
#else
|
2021-12-07 16:17:20 +00:00
|
|
|
// we use a uv_prepare_t because it fires before blocking for new io events unconditionally
|
|
|
|
// we want to match what linux does, using a uv_check_t does not suffice as the order of
|
|
|
|
// operations is not what we need.
|
|
|
|
using event_t = uvw::PrepareEvent;
|
|
|
|
auto handle = m_Impl->resource<uvw::PrepareHandle>();
|
2021-03-02 02:06:20 +00:00
|
|
|
#endif
|
2022-07-28 16:07:38 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
if (!handle)
|
2021-01-11 23:13:22 +00:00
|
|
|
return false;
|
2021-03-02 02:06:20 +00:00
|
|
|
|
|
|
|
handle->on<event_t>([netif = std::move(netif), handler = std::move(handler)](
|
|
|
|
const event_t&, [[maybe_unused]] auto& handle) {
|
2022-07-28 16:07:38 +00:00
|
|
|
for (auto pkt = netif->ReadNextPacket(); true; pkt = netif->ReadNextPacket())
|
2021-03-02 02:06:20 +00:00
|
|
|
{
|
2022-07-28 16:07:38 +00:00
|
|
|
if (pkt.empty())
|
|
|
|
return;
|
2021-03-02 02:06:20 +00:00
|
|
|
if (handler)
|
|
|
|
handler(std::move(pkt));
|
2021-12-07 16:17:20 +00:00
|
|
|
// on windows/apple, vpn packet io does not happen as an io action that wakes up the event
|
|
|
|
// loop thus, we must manually wake up the event loop when we get a packet on our interface.
|
2022-07-28 16:07:38 +00:00
|
|
|
// on linux/android this is a nop
|
2021-12-07 16:17:20 +00:00
|
|
|
netif->MaybeWakeUpperLayers();
|
2021-03-02 02:06:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-29 20:40:25 +00:00
|
|
|
#ifdef __linux__
|
2021-03-02 02:06:20 +00:00
|
|
|
handle->start(uvw::PollHandle::Event::READABLE);
|
|
|
|
#else
|
|
|
|
handle->start();
|
|
|
|
#endif
|
|
|
|
|
2021-01-11 23:13:22 +00:00
|
|
|
return true;
|
2019-08-22 11:18:05 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 15:21:52 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
Loop::call_soon(std::function<void(void)> f)
|
2019-12-10 15:21:52 +00:00
|
|
|
{
|
2020-06-16 11:28:20 +00:00
|
|
|
if (not m_EventLoopThreadID.has_value())
|
|
|
|
{
|
|
|
|
m_LogicCalls.tryPushBack(f);
|
2021-03-02 02:06:20 +00:00
|
|
|
m_WakeUp->send();
|
2020-06-16 11:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-02 07:02:59 +00:00
|
|
|
if (inEventLoop() and m_LogicCalls.full())
|
2020-06-16 11:28:20 +00:00
|
|
|
{
|
2020-10-21 21:31:57 +00:00
|
|
|
FlushLogic();
|
2020-06-16 11:28:20 +00:00
|
|
|
}
|
2020-10-21 21:31:57 +00:00
|
|
|
m_LogicCalls.pushBack(f);
|
2021-03-02 02:06:20 +00:00
|
|
|
m_WakeUp->send();
|
2019-12-10 15:21:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
// Sets `handle` to a new uvw UDP handle, first initiating a close and then disowning the handle
|
|
|
|
// if already set, allocating the resource, and setting the receive event on it.
|
2020-06-09 16:59:49 +00:00
|
|
|
void
|
2021-03-02 02:06:20 +00:00
|
|
|
UDPHandle::reset_handle(uvw::Loop& loop)
|
|
|
|
{
|
|
|
|
if (handle)
|
|
|
|
handle->close();
|
|
|
|
handle = loop.resource<uvw::UDPHandle>();
|
|
|
|
handle->on<uvw::UDPDataEvent>([this](auto& event, auto& /*handle*/) {
|
|
|
|
on_recv(
|
|
|
|
*this,
|
2021-05-30 17:29:00 +00:00
|
|
|
SockAddr{event.sender.ip, huint16_t{static_cast<uint16_t>(event.sender.port)}},
|
2021-03-02 02:06:20 +00:00
|
|
|
OwnedBuffer{std::move(event.data), event.length});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
llarp::uv::UDPHandle::UDPHandle(uvw::Loop& loop, ReceiveFunc rf) : llarp::UDPHandle{std::move(rf)}
|
2020-06-09 16:59:49 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
reset_handle(loop);
|
|
|
|
}
|
2020-06-09 16:59:49 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
bool
|
|
|
|
UDPHandle::listen(const SockAddr& addr)
|
|
|
|
{
|
|
|
|
if (handle->active())
|
|
|
|
reset_handle(handle->loop());
|
|
|
|
|
2022-08-18 14:31:39 +00:00
|
|
|
auto err = handle->on<uvw::ErrorEvent>([addr](auto& event, auto&) {
|
|
|
|
throw llarp::util::bind_socket_error{
|
|
|
|
fmt::format("failed to bind udp socket on {}: {}", addr, event.what())};
|
2021-03-02 02:06:20 +00:00
|
|
|
});
|
|
|
|
handle->bind(*static_cast<const sockaddr*>(addr));
|
2022-08-18 14:31:39 +00:00
|
|
|
handle->recv();
|
2021-03-02 02:06:20 +00:00
|
|
|
handle->erase(err);
|
2022-08-18 14:31:39 +00:00
|
|
|
return true;
|
2021-03-02 02:06:20 +00:00
|
|
|
}
|
2020-06-09 16:59:49 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
bool
|
|
|
|
UDPHandle::send(const SockAddr& to, const llarp_buffer_t& buf)
|
|
|
|
{
|
|
|
|
return handle->trySend(
|
|
|
|
*static_cast<const sockaddr*>(to),
|
|
|
|
const_cast<char*>(reinterpret_cast<const char*>(buf.base)),
|
|
|
|
buf.sz)
|
|
|
|
>= 0;
|
2020-06-09 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-02 02:06:20 +00:00
|
|
|
UDPHandle::close()
|
2020-06-09 16:59:49 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
handle->close();
|
|
|
|
handle.reset();
|
2020-06-09 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
UDPHandle::~UDPHandle()
|
2020-06-09 16:59:49 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
close();
|
|
|
|
}
|
2020-06-09 16:59:49 +00:00
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
std::shared_ptr<llarp::EventLoopWakeup>
|
|
|
|
Loop::make_waker(std::function<void()> callback)
|
|
|
|
{
|
|
|
|
return std::static_pointer_cast<llarp::EventLoopWakeup>(
|
|
|
|
std::make_shared<UVWakeup>(*m_Impl, std::move(callback)));
|
2020-06-09 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
std::shared_ptr<EventLoopRepeater>
|
|
|
|
Loop::make_repeater()
|
2021-02-22 13:26:32 +00:00
|
|
|
{
|
2021-03-02 02:06:20 +00:00
|
|
|
return std::static_pointer_cast<EventLoopRepeater>(std::make_shared<UVRepeater>(*m_Impl));
|
2021-02-22 13:26:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
bool
|
2021-03-02 07:02:59 +00:00
|
|
|
Loop::inEventLoop() const
|
2021-02-22 13:26:32 +00:00
|
|
|
{
|
2021-04-26 10:08:02 +00:00
|
|
|
if (m_EventLoopThreadID)
|
|
|
|
return *m_EventLoopThreadID == std::this_thread::get_id();
|
2021-04-26 10:19:46 +00:00
|
|
|
// assume we are in it because we haven't started up yet
|
2021-04-26 10:08:02 +00:00
|
|
|
return true;
|
2021-02-22 13:26:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
} // namespace llarp::uv
|