mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
bdc54835c2
- updated CMake build script - builds with Microsoft C++ 19.1x. such builds require Windows 8.1 or later unless you have the .NET Server 2003-toolset (v141_xp) - windows port requires a C++17 compiler since cpp17::filesystem is POSIX-only - HAVE_CXX17_FILESYSTEM manual toggle in CMake. You must manually specify where std::[experimental::]filesystem is defined in LDFLAGS or CMAKE_x_LINKER_FLAGS. - IPv6 support can be added at any time, and the windows sdk still has that inline getaddrinfo(3) if it can't find a suitable IPv6 stack. - inline code for mingw-w64: there's a few bits and pieces still missing simply because mingw-w64 derives its windows sdk from wine and reactos, and then writing all the newer stuff into it by hand straight from the MSDN manpages. - misc. C++11 stuff (nullptr and friends) - Internal file handling code takes UTF-8 or plain 8-bit text, NTFS is UTF-16, so std::filesystem::path::c_str() is wchar_t. That's no good unless you first call std::filesystem::path::string(). - implemented getifaddrs(3) and if_nametoindex(3) on top of GetAdapters[Info|Addresses](2). - updated readme with new info BONUS: may implement Solaris/illumos IOCP someday... -despair86
105 lines
2.2 KiB
C++
105 lines
2.2 KiB
C++
#include <llarp/ev.h>
|
|
#include <llarp/logic.h>
|
|
#include "mem.hpp"
|
|
|
|
#ifdef __linux__
|
|
#include "ev_epoll.hpp"
|
|
#endif
|
|
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || (__APPLE__ && __MACH__)
|
|
#include "ev_kqueue.hpp"
|
|
#endif
|
|
#if defined(_WIN32) || defined(_WIN64) || defined(__NT__)
|
|
#include "ev_win32.hpp"
|
|
#endif
|
|
|
|
void
|
|
llarp_ev_loop_alloc(struct llarp_ev_loop **ev)
|
|
{
|
|
#ifdef __linux__
|
|
*ev = new llarp_epoll_loop;
|
|
#endif
|
|
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || (__APPLE__ && __MACH__)
|
|
*ev = new llarp_kqueue_loop;
|
|
#endif
|
|
#if defined(_WIN32) || defined(_WIN64) || defined(__NT__)
|
|
*ev = new llarp_win32_loop;
|
|
#endif
|
|
// a) I assume that the libre fork of Solaris is still
|
|
// 5.10, and b) the current commercial version is 5.11, naturally.
|
|
// -despair86
|
|
#if defined(__SunOS_5_10) || defined(__SunOS_5_11)
|
|
*ev = new llarp_sun_iocp_loop;
|
|
#endif
|
|
(*ev)->init();
|
|
}
|
|
|
|
void
|
|
llarp_ev_loop_free(struct llarp_ev_loop **ev)
|
|
{
|
|
delete *ev;
|
|
*ev = nullptr;
|
|
}
|
|
|
|
int
|
|
llarp_ev_loop_run(struct llarp_ev_loop *ev, struct llarp_logic *logic)
|
|
{
|
|
while(true)
|
|
{
|
|
if(ev->tick(100) == -1)
|
|
break;
|
|
llarp_logic_tick(logic);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
llarp_ev_loop_run_single_process(struct llarp_ev_loop *ev,
|
|
struct llarp_threadpool *tp,
|
|
struct llarp_logic *logic)
|
|
{
|
|
while(true)
|
|
{
|
|
if(ev->tick(10) == -1)
|
|
return;
|
|
llarp_logic_tick(logic);
|
|
llarp_threadpool_tick(tp);
|
|
}
|
|
}
|
|
|
|
int
|
|
llarp_ev_add_udp(struct llarp_ev_loop *ev, struct llarp_udp_io *udp,
|
|
const struct sockaddr *src)
|
|
{
|
|
udp->parent = ev;
|
|
if(ev->udp_listen(udp, src))
|
|
return 0;
|
|
return -1;
|
|
}
|
|
|
|
int
|
|
llarp_ev_close_udp(struct llarp_udp_io *udp)
|
|
{
|
|
if(udp->parent->udp_close(udp))
|
|
return 0;
|
|
return -1;
|
|
}
|
|
|
|
void
|
|
llarp_ev_loop_stop(struct llarp_ev_loop *loop)
|
|
{
|
|
loop->stop();
|
|
}
|
|
|
|
int
|
|
llarp_ev_udp_sendto(struct llarp_udp_io *udp, const sockaddr *to,
|
|
const void *buf, size_t sz)
|
|
{
|
|
auto ret = static_cast< llarp::ev_io * >(udp->impl)->sendto(to, buf, sz);
|
|
if(ret == -1)
|
|
{
|
|
llarp::LogWarn("sendto failed ", strerror(errno));
|
|
errno = 0;
|
|
}
|
|
return ret;
|
|
}
|