Loading src/event/poll.cpp +20 −3 Changes for src/event/poll.cpp: 20 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -707,11 +707,25 @@ namespace netplus { // ------------------------------------------------------------ // Signal handler // ------------------------------------------------------------ // ------------------------------------------------------------ // Signal handler — MUST be async-signal-safe. // // Acquiring mutexes here deadlocks if the signal is // delivered to a thread that already holds the lock. // Only set the atomic flag; cleanup happens in // runEventloop() after all threads have joined. // ------------------------------------------------------------ #ifndef _WIN32 static void signalHandler(int signum) { if (signum != SIGINT) return; event::Running = false; } #endif // Called from runEventloop() AFTER all worker threads have // joined — safe to acquire any lock. static void cleanupConnections() { std::vector<socket*> servers; std::vector<std::shared_ptr<con>> conns; Loading @@ -734,10 +748,7 @@ namespace netplus { std::lock_guard<std::recursive_mutex> lk(c->event_mutex); safeCloseSocket(c); } event::Running = false; } #endif // ------------------------------------------------------------ // event class Loading Loading @@ -833,6 +844,9 @@ namespace netplus { for (auto& t : threadpool) CloseHandle(t); // All worker threads have exited — safe to clean up. cleanupConnections(); #else pthread_attr_t attr; pthread_attr_init(&attr); Loading @@ -858,6 +872,9 @@ namespace netplus { for (auto& t : threadpool) pthread_join(t, nullptr); // All worker threads have exited — safe to clean up. cleanupConnections(); #endif if (event::Restart) { Loading Loading
src/event/poll.cpp +20 −3 Changes for src/event/poll.cpp: 20 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -707,11 +707,25 @@ namespace netplus { // ------------------------------------------------------------ // Signal handler // ------------------------------------------------------------ // ------------------------------------------------------------ // Signal handler — MUST be async-signal-safe. // // Acquiring mutexes here deadlocks if the signal is // delivered to a thread that already holds the lock. // Only set the atomic flag; cleanup happens in // runEventloop() after all threads have joined. // ------------------------------------------------------------ #ifndef _WIN32 static void signalHandler(int signum) { if (signum != SIGINT) return; event::Running = false; } #endif // Called from runEventloop() AFTER all worker threads have // joined — safe to acquire any lock. static void cleanupConnections() { std::vector<socket*> servers; std::vector<std::shared_ptr<con>> conns; Loading @@ -734,10 +748,7 @@ namespace netplus { std::lock_guard<std::recursive_mutex> lk(c->event_mutex); safeCloseSocket(c); } event::Running = false; } #endif // ------------------------------------------------------------ // event class Loading Loading @@ -833,6 +844,9 @@ namespace netplus { for (auto& t : threadpool) CloseHandle(t); // All worker threads have exited — safe to clean up. cleanupConnections(); #else pthread_attr_t attr; pthread_attr_init(&attr); Loading @@ -858,6 +872,9 @@ namespace netplus { for (auto& t : threadpool) pthread_join(t, nullptr); // All worker threads have exited — safe to clean up. cleanupConnections(); #endif if (event::Restart) { Loading