Loading src/event/epoll.cpp +14 −3 Changes for src/event/epoll.cpp: 14 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -643,12 +643,22 @@ namespace netplus { void eventapi::DisconnectEvent(con&, const int, ULONG_PTR) {} // ------------------------------------------------------------ // Signal handler (NO LOCKED CLOSE!) // 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. // ------------------------------------------------------------ static void signalHandler(int signum) { if (signum != SIGINT) return; event::Running = false; } // 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 @@ -671,8 +681,6 @@ namespace netplus { std::lock_guard<std::mutex> lk(c->event_mutex); safeCloseSocket(c); } event::Running = false; } // ------------------------------------------------------------ Loading Loading @@ -765,6 +773,9 @@ namespace netplus { for (auto& t : threadpool) pthread_join(t, nullptr); // All worker threads have exited — safe to clean up. cleanupConnections(); // Close all epoll FDs (not just the last one) for (auto& kv : eargs.ssocket) close(kv.first); Loading Loading
src/event/epoll.cpp +14 −3 Changes for src/event/epoll.cpp: 14 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -643,12 +643,22 @@ namespace netplus { void eventapi::DisconnectEvent(con&, const int, ULONG_PTR) {} // ------------------------------------------------------------ // Signal handler (NO LOCKED CLOSE!) // 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. // ------------------------------------------------------------ static void signalHandler(int signum) { if (signum != SIGINT) return; event::Running = false; } // 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 @@ -671,8 +681,6 @@ namespace netplus { std::lock_guard<std::mutex> lk(c->event_mutex); safeCloseSocket(c); } event::Running = false; } // ------------------------------------------------------------ Loading Loading @@ -765,6 +773,9 @@ namespace netplus { for (auto& t : threadpool) pthread_join(t, nullptr); // All worker threads have exited — safe to clean up. cleanupConnections(); // Close all epoll FDs (not just the last one) for (auto& kv : eargs.ssocket) close(kv.first); Loading