Commit 7c43b073 authored by jan.koester's avatar jan.koester
Browse files

test

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

@@ -734,10 +748,7 @@ namespace netplus {
            std::lock_guard<std::recursive_mutex> lk(c->event_mutex);
            safeCloseSocket(c);
        }

        event::Running = false;
    }
    #endif

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