Loading src/event/iocp.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment(lib, "Ws2_32.lib") #include <signal.h> #include <atomic> #include <thread> #include <chrono> Loading Loading @@ -74,6 +76,10 @@ namespace netplus { static std::mutex g_stateMutex; static std::unordered_map<event*, std::unique_ptr<EventState>> g_states; // Set by runEventloop() so the signal handler can post wakeup completions. static HANDLE g_wakeup_iocp = nullptr; static int g_wakeup_workers = 0; static EventState* ST(event* ev) { std::lock_guard<std::mutex> lk(g_stateMutex); auto it = g_states.find(ev); Loading Loading @@ -763,6 +769,16 @@ namespace netplus { WSACleanup(); } static void iocpSignalHandler(int signum) { if (signum != SIGINT) return; event::Running = false; // Wake all blocked GetQueuedCompletionStatus calls immediately. if (g_wakeup_iocp) { for (int i = 0; i < g_wakeup_workers; ++i) PostQueuedCompletionStatus(g_wakeup_iocp, 0, 0, nullptr); } } void event::runEventloop(ULONG_PTR /*args*/) { init_state(this); Loading @@ -771,6 +787,10 @@ namespace netplus { Running = true; g_wakeup_iocp = st->iocp; g_wakeup_workers = st->threads; signal(SIGINT, iocpSignalHandler); // Start dedicated accept thread per server socket for (auto* ss : _ServerSockets) { if (!ss) continue; Loading @@ -796,6 +816,9 @@ namespace netplus { if (t.joinable()) t.join(); } st->acceptThreads.clear(); g_wakeup_iocp = nullptr; g_wakeup_workers = 0; } // ================================================================ Loading Loading
src/event/iocp.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment(lib, "Ws2_32.lib") #include <signal.h> #include <atomic> #include <thread> #include <chrono> Loading Loading @@ -74,6 +76,10 @@ namespace netplus { static std::mutex g_stateMutex; static std::unordered_map<event*, std::unique_ptr<EventState>> g_states; // Set by runEventloop() so the signal handler can post wakeup completions. static HANDLE g_wakeup_iocp = nullptr; static int g_wakeup_workers = 0; static EventState* ST(event* ev) { std::lock_guard<std::mutex> lk(g_stateMutex); auto it = g_states.find(ev); Loading Loading @@ -763,6 +769,16 @@ namespace netplus { WSACleanup(); } static void iocpSignalHandler(int signum) { if (signum != SIGINT) return; event::Running = false; // Wake all blocked GetQueuedCompletionStatus calls immediately. if (g_wakeup_iocp) { for (int i = 0; i < g_wakeup_workers; ++i) PostQueuedCompletionStatus(g_wakeup_iocp, 0, 0, nullptr); } } void event::runEventloop(ULONG_PTR /*args*/) { init_state(this); Loading @@ -771,6 +787,10 @@ namespace netplus { Running = true; g_wakeup_iocp = st->iocp; g_wakeup_workers = st->threads; signal(SIGINT, iocpSignalHandler); // Start dedicated accept thread per server socket for (auto* ss : _ServerSockets) { if (!ss) continue; Loading @@ -796,6 +816,9 @@ namespace netplus { if (t.joinable()) t.join(); } st->acceptThreads.clear(); g_wakeup_iocp = nullptr; g_wakeup_workers = 0; } // ================================================================ Loading