2018-01-25 16:24:33 +00:00
|
|
|
#include <llarp/ev.h>
|
2018-02-01 13:21:00 +00:00
|
|
|
#include "mem.hpp"
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-04-30 13:18:57 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include "ev_epoll.hpp"
|
|
|
|
#endif
|
2018-05-16 16:41:20 +00:00
|
|
|
#ifdef __FreeBSD__
|
2018-04-30 13:18:57 +00:00
|
|
|
#include "ev_kqueue.hpp"
|
|
|
|
#endif
|
|
|
|
|
2018-01-08 13:49:05 +00:00
|
|
|
extern "C" {
|
2018-05-18 17:10:48 +00:00
|
|
|
|
2018-01-29 14:27:24 +00:00
|
|
|
void llarp_ev_loop_alloc(struct llarp_ev_loop **ev) {
|
2018-04-30 13:18:57 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
*ev = new llarp_epoll_loop;
|
|
|
|
#endif
|
2018-05-16 16:41:20 +00:00
|
|
|
#ifdef __FreeBSD__
|
2018-04-30 13:18:57 +00:00
|
|
|
*ev = new llarp_kqueue_loop;
|
|
|
|
#endif
|
2018-05-18 13:17:58 +00:00
|
|
|
(*ev)->init();
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-01-29 14:27:24 +00:00
|
|
|
void llarp_ev_loop_free(struct llarp_ev_loop **ev) {
|
2018-04-30 13:18:57 +00:00
|
|
|
delete *ev;
|
2018-01-29 14:27:24 +00:00
|
|
|
*ev = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-30 16:14:20 +00:00
|
|
|
int llarp_ev_loop_run(struct llarp_ev_loop *ev) { return ev->run(); }
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-05-16 16:41:20 +00:00
|
|
|
int llarp_ev_add_udp(struct llarp_ev_loop *ev,
|
|
|
|
struct llarp_udp_io * udp) {
|
|
|
|
udp->parent = ev;
|
|
|
|
if(ev->udp_listen(udp)) return 0;
|
|
|
|
return -1;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2018-01-19 16:51:27 +00:00
|
|
|
|
2018-05-16 16:41:20 +00:00
|
|
|
int llarp_ev_close_udp_close(struct llarp_udp_io * udp) {
|
|
|
|
if(udp->parent->udp_close(udp)) return 0;
|
|
|
|
return -1;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2018-01-29 14:19:00 +00:00
|
|
|
|
2018-04-30 13:18:57 +00:00
|
|
|
void llarp_ev_loop_stop(struct llarp_ev_loop *loop) { loop->stop(); }
|
2018-05-18 17:10:48 +00:00
|
|
|
|
|
|
|
int llarp_ev_udp_sendto(struct llarp_udp_io * udp, const sockaddr * to, const void * buf, size_t sz)
|
|
|
|
{
|
|
|
|
return static_cast<llarp::ev_io*>(udp->impl)->sendto(to, buf,sz);
|
|
|
|
}
|
|
|
|
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|