mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.1 KiB
C++
103 lines
2.1 KiB
C++
4 years ago
|
#pragma once
|
||
|
#include "ev.hpp"
|
||
4 years ago
|
#include "udp_handle.hpp"
|
||
4 years ago
|
#include <llarp/util/thread/queue.hpp>
|
||
|
#include <llarp/util/meta/memfn.hpp>
|
||
5 years ago
|
|
||
4 years ago
|
#include <uvw/loop.h>
|
||
|
#include <uvw/async.h>
|
||
|
#include <uvw/poll.h>
|
||
|
#include <uvw/udp.h>
|
||
|
|
||
|
#include <functional>
|
||
5 years ago
|
#include <map>
|
||
4 years ago
|
#include <vector>
|
||
5 years ago
|
|
||
4 years ago
|
namespace llarp::uv
|
||
5 years ago
|
{
|
||
4 years ago
|
class UVWakeup;
|
||
4 years ago
|
class UVRepeater;
|
||
4 years ago
|
|
||
2 years ago
|
class Loop : public llarp::EventLoop
|
||
5 years ago
|
{
|
||
4 years ago
|
public:
|
||
4 years ago
|
using Callback = std::function<void()>;
|
||
5 years ago
|
|
||
4 years ago
|
Loop(size_t queue_size);
|
||
5 years ago
|
|
||
2 years ago
|
virtual void
|
||
4 years ago
|
run() override;
|
||
5 years ago
|
|
||
|
bool
|
||
|
running() const override;
|
||
|
|
||
3 years ago
|
llarp_time_t
|
||
|
time_now() const override
|
||
|
{
|
||
|
return m_Impl->now();
|
||
|
}
|
||
|
|
||
5 years ago
|
void
|
||
4 years ago
|
call_later(llarp_time_t delay_ms, std::function<void(void)> callback) override;
|
||
5 years ago
|
|
||
|
void
|
||
4 years ago
|
tick_event_loop();
|
||
5 years ago
|
|
||
5 years ago
|
void
|
||
|
stop() override;
|
||
|
|
||
5 years ago
|
bool
|
||
5 years ago
|
add_ticker(std::function<void(void)> ticker) override;
|
||
5 years ago
|
|
||
5 years ago
|
bool
|
||
4 years ago
|
add_network_interface(
|
||
|
std::shared_ptr<llarp::vpn::NetworkInterface> netif,
|
||
|
std::function<void(llarp::net::IPPacket)> handler) override;
|
||
5 years ago
|
|
||
5 years ago
|
void
|
||
5 years ago
|
call_soon(std::function<void(void)> f) override;
|
||
5 years ago
|
|
||
4 years ago
|
std::shared_ptr<llarp::EventLoopWakeup>
|
||
|
make_waker(std::function<void()> callback) override;
|
||
4 years ago
|
|
||
4 years ago
|
std::shared_ptr<EventLoopRepeater>
|
||
|
make_repeater() override;
|
||
|
|
||
2 years ago
|
virtual std::shared_ptr<llarp::UDPHandle>
|
||
4 years ago
|
make_udp(UDPReceiveFunc on_recv) override;
|
||
4 years ago
|
|
||
4 years ago
|
void
|
||
|
FlushLogic();
|
||
|
|
||
4 years ago
|
std::shared_ptr<uvw::Loop>
|
||
|
MaybeGetUVWLoop() override;
|
||
4 years ago
|
|
||
4 years ago
|
bool
|
||
4 years ago
|
inEventLoop() const override;
|
||
4 years ago
|
|
||
2 years ago
|
protected:
|
||
4 years ago
|
std::shared_ptr<uvw::Loop> m_Impl;
|
||
2 years ago
|
std::optional<std::thread::id> m_EventLoopThreadID;
|
||
|
|
||
|
private:
|
||
4 years ago
|
std::shared_ptr<uvw::AsyncHandle> m_WakeUp;
|
||
5 years ago
|
std::atomic<bool> m_Run;
|
||
|
using AtomicQueue_t = llarp::thread::Queue<std::function<void(void)>>;
|
||
5 years ago
|
AtomicQueue_t m_LogicCalls;
|
||
5 years ago
|
|
||
|
#ifdef LOKINET_DEBUG
|
||
|
uint64_t last_time;
|
||
|
uint64_t loop_run_count;
|
||
|
#endif
|
||
5 years ago
|
std::atomic<uint32_t> m_nextID;
|
||
5 years ago
|
|
||
5 years ago
|
std::map<uint32_t, Callback> m_pendingCalls;
|
||
5 years ago
|
|
||
4 years ago
|
std::unordered_map<int, std::shared_ptr<uvw::PollHandle>> m_Polls;
|
||
4 years ago
|
|
||
3 years ago
|
void
|
||
|
wakeup() override;
|
||
5 years ago
|
};
|
||
|
|
||
4 years ago
|
} // namespace llarp::uv
|