From 3d62460f42e9a0bf01d7ff54cf27c8b7bb745c11 Mon Sep 17 00:00:00 2001 From: Rick V Date: Mon, 11 Mar 2019 13:41:05 -0500 Subject: [PATCH] that didn't even fix the abseil shite in fact, the *original* issue was resolved ages ago This reverts commit 2373698ea91feb29158caa1634335858becb038d. yeah this was a solution in search of a problem that no longer exists --- llarp/ev/ev_win32.cpp | 60 ++++++------------------------------------- llarp/ev/ev_win32.hpp | 11 ++++---- 2 files changed, 14 insertions(+), 57 deletions(-) diff --git a/llarp/ev/ev_win32.cpp b/llarp/ev/ev_win32.cpp index 402fc3d74..34e85bd07 100644 --- a/llarp/ev/ev_win32.cpp +++ b/llarp/ev/ev_win32.cpp @@ -12,12 +12,13 @@ static CRITICAL_SECTION HandlerMtx; std::list< win32_tun_io* > tun_listeners; void -win32_tun_io::begin_tun_loop(int nThreads) +begin_tun_loop(int nThreads) { kThreadPool = new HANDLE[nThreads]; for(int i = 0; i < nThreads; ++i) { - kThreadPool[i] = CreateThread(nullptr, 0, &tun_ev_loop, this, 0, nullptr); + kThreadPool[i] = + CreateThread(nullptr, 0, &tun_ev_loop, nullptr, 0, nullptr); } llarp::LogInfo("created ", nThreads, " threads for TUN event queue"); poolSize = nThreads; @@ -123,48 +124,11 @@ win32_tun_io::read(byte_t* buf, size_t sz) ReadFile(tunif->tun_fd, buf, sz, nullptr, &pkt->pkt); } -static void -tun_ev_tick_and_flush(void* user) -{ - llarp_tun_io* tun = static_cast< llarp_tun_io* >(user); - if(tun->tick) - tun->tick(tun); - tun->flush(tun); -} - -struct tun_pkt_t -{ - std::vector< byte_t > pkt; - llarp_tun_io* tun; - - tun_pkt_t(llarp_tun_io* t, const byte_t* buf, size_t sz) : tun(t), pkt(sz) - { - std::copy_n(buf, sz, pkt.begin()); - } - - static void - recv_pkt(void* user) - { - tun_pkt_t* pkt = static_cast< tun_pkt_t* >(user); - pkt->Recv(); - delete pkt; - } - - private: - void - Recv() - { - llarp_buffer_t buf(pkt); - if(tun->recvpkt) - tun->recvpkt(tun, buf); - } -} - // and now the event loop itself extern "C" DWORD FAR PASCAL -tun_ev_loop(void* user) +tun_ev_loop(void* unused) { - win32_tun_io* tun_io = static_cast< win32_tun_io* >(user); + UNREFERENCED_PARAMETER(unused); DWORD size = 0; OVERLAPPED* ovl = nullptr; @@ -184,14 +148,11 @@ tun_ev_loop(void* user) // of the tun logic for(const auto& tun : tun_listeners) { - /* EnterCriticalSection(&HandlerMtx); if(tun->t->tick) tun->t->tick(tun->t); tun->flush_write(); LeaveCriticalSection(&HandlerMtx); - */ - tun_io->logic->queue_job({tun->t, &tun_ev_tick_and_flush}); } continue; // let's go at it once more } @@ -212,10 +173,8 @@ tun_ev_loop(void* user) continue; } // EnterCriticalSection(&HandlerMtx); - tun_pkt_t* recv_pkt = new tun_pkt_t(ev->t, pkt->buf, size); - tun_io->logic->queue_job({recv_pkt, &tun_pkt_t::recv_pkt}); - // if(ev->t->recvpkt) - // ev->t->recvpkt(ev->t, llarp_buffer_t(pkt->buf, size)); + if(ev->t->recvpkt) + ev->t->recvpkt(ev->t, llarp_buffer_t(pkt->buf, size)); ev->read(ev->readbuf, sizeof(ev->readbuf)); // LeaveCriticalSection(&HandlerMtx); } @@ -226,14 +185,11 @@ tun_ev_loop(void* user) ev->read(ev->readbuf, sizeof(ev->readbuf)); // LeaveCriticalSection(&HandlerMtx); } - /* EnterCriticalSection(&HandlerMtx); if(ev->t->tick) ev->t->tick(ev->t); ev->flush_write(); LeaveCriticalSection(&HandlerMtx); - */ - tun_io->logic->queue_job({ev->t, &tun_ev_tick_and_flush}); delete pkt; // don't leak } llarp::LogDebug("exit TUN event loop thread from system managed thread pool"); @@ -701,4 +657,4 @@ llarp_win32_loop::stop() upoll_destroy(upollfd); upollfd = nullptr; llarp::LogDebug("destroy upoll"); -} +} \ No newline at end of file diff --git a/llarp/ev/ev_win32.hpp b/llarp/ev/ev_win32.hpp index d3ac84c34..0d9c31fd8 100644 --- a/llarp/ev/ev_win32.hpp +++ b/llarp/ev/ev_win32.hpp @@ -23,11 +23,14 @@ struct asio_evt_pkt }; extern "C" DWORD FAR PASCAL -tun_ev_loop(void* ev); +tun_ev_loop(void* unused); void exit_tun_loop(); +void +begin_tun_loop(int nThreads); + namespace llarp { struct udp_listener : public ev_io @@ -57,12 +60,10 @@ namespace llarp struct win32_tun_io { llarp_tun_io* t; - llarp::Logic* logic; device* tunif; byte_t readbuf[EV_READ_BUF_SZ] = {0}; - win32_tun_io(llarp_tun_io* tio, llarp::Logic* l) - : t(tio), logic(l), tunif(tuntap_init()){}; + win32_tun_io(llarp_tun_io* tio) : t(tio), tunif(tuntap_init()){}; bool queue_write(const byte_t* buf, size_t sz); @@ -151,4 +152,4 @@ struct llarp_win32_loop : public llarp_ev_loop stop(); }; -#endif +#endif \ No newline at end of file