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