Commit 176fc13e authored by jan.koester's avatar jan.koester
Browse files

test

parent bb454633
Loading
Loading
Loading
Loading
+14 −3
Changes for src/event/epoll.cpp: 14 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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;

@@ -671,8 +681,6 @@ namespace netplus {
            std::lock_guard<std::mutex> lk(c->event_mutex);
            safeCloseSocket(c);
        }

        event::Running = false;
    }

    // ------------------------------------------------------------
@@ -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);