Commit bb454633 authored by jan.koester's avatar jan.koester
Browse files

test

parent 0dc04921
Loading
Loading
Loading
Loading
+13 −4
Changes for src/event/kqueue.cpp: 13 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -734,16 +734,22 @@ namespace netplus {
    }

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

        // Stop worker loops FIRST so they don't spin on
        // EV_EOF events while we close sockets below.
        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;

@@ -853,6 +859,9 @@ MAINWORKERLOOP:
    for (auto& t : threadpool)
        pthread_join(t, nullptr);

    // All worker threads have exited — safe to clean up.
    netplus::cleanupConnections();

    // Close all kqueue FDs (not just the last one)
    for (auto& kv : eargs.ssocket)
        close(kv.first);