1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/ev.hpp

64 lines
947 B
C++
Raw Normal View History

2018-04-30 15:18:57 +02:00
#ifndef LLARP_EV_HPP
#define LLARP_EV_HPP
#include <llarp/ev.h>
#ifndef _MSC_VER
2018-04-30 15:18:57 +02:00
#include <unistd.h>
#endif
#include <list>
2018-04-30 15:18:57 +02:00
namespace llarp
{
struct ev_io
{
#ifndef _WIN32
int fd;
ev_io(int f) : fd(f){};
#else
SOCKET fd;
ev_io(SOCKET f) : fd(f){};
#endif
virtual int
read(void* buf, size_t sz) = 0;
virtual int
sendto(const sockaddr* dst, const void* data, size_t sz) = 0;
virtual ~ev_io()
{
#ifndef _WIN32
::close(fd);
#else
closesocket(fd);
#endif
};
};
2018-04-30 18:14:20 +02:00
}; // namespace llarp
2018-04-30 15:18:57 +02:00
struct llarp_ev_loop
{
virtual bool
init() = 0;
virtual int
run() = 0;
2018-06-06 14:46:26 +02:00
virtual int
2018-06-06 23:23:57 +02:00
tick(int ms) = 0;
2018-06-06 14:46:26 +02:00
virtual void
stop() = 0;
2018-04-30 15:18:57 +02:00
virtual bool
2018-05-23 15:49:00 +02:00
udp_listen(llarp_udp_io* l, const sockaddr* src) = 0;
virtual bool
udp_close(llarp_udp_io* l) = 0;
virtual bool
close_ev(llarp::ev_io* ev) = 0;
2018-04-30 18:14:20 +02:00
virtual ~llarp_ev_loop(){};
std::list< llarp_udp_io* > udp_listeners;
2018-04-30 15:18:57 +02:00
};
#endif