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

test

parent faee8b82
Loading
Loading
Loading
Loading
+15 −13
Changes for src/event/kqueue.cpp: 15 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -352,12 +352,9 @@ namespace netplus {
class EventWorker {
public:
    EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) {

        poll pollptr(eargs->ssocket, eargs->event, eargs->pollfd, eargs->timeout);

        int wait = 0;

            // In EventWorker::EventWorker:
        while (RUNNING) {
            try {
                wait = pollptr.waitEventHandler(eargs->timeout);
@@ -365,43 +362,48 @@ namespace netplus {
                    try {
                        int events = pollptr.pollState(i);

                            // Check for listener socket (data.ptr is nullptr)
                        // 1. Check for listener socket (data.ptr is nullptr)
                        if (events == pollapi::EventHandlerStatus::EVCON) {
                            pollptr.ConnectEventHandler(i, tid, args);
                            continue;
                        }

                        // 2. Retrieve event flags (may throw on EV_ERROR)
                        events = pollptr.getEventFlags(i);

                        // 3. 🚨 NEW: Handle EV_EOF (Graceful Connection Close/Hangup)
                        // If EV_EOF is set, close the connection and skip other handlers.
                        if (events & EV_EOF) {
                            pollptr.CloseEventHandler(i, tid, args);
                            continue;
                        }

                            // Prioritize read events (new data from client)
                        // 4. Prioritize read events (new data from client)
                        if (events & EVFILT_READ) {
                            pollptr.ReadEventHandler(i, tid, args);
                        }

                            // Handle write events (ready to send data)
                        // 5. Handle write events (ready to send data)
                        if (events & EVFILT_WRITE) {
                            pollptr.WriteEventHandler(i, tid, args);
                        }

                            // FALLBACK/DEFAULT HANDLER
                            NetException e;
                            e[NetException::Error] << "EventWorker: Unhandled epoll event type!";
                            throw e;
                        // No need for a fatal throw here, as all events (READ, WRITE, EOF, ERROR) are handled.

                    } catch (NetException& e) {
                        // Catches exceptions from getEventFlags (EV_ERROR) and event handlers.
                        std::cerr << e.what() << std::endl;
                        pollptr.CloseEventHandler(i, tid, args);
                             if(e.getErrorType()==NetException::Critical)
                                 throw e;

                        if (e.getErrorType() == NetException::Critical) {
                            throw e; // Re-throw critical error to kill the worker thread
                        }
                    }
                }
            } catch (NetException& e) {
                    std::cerr << e.what() << std::endl;
                // Catches critical exceptions re-thrown from inner block or waitEventHandler failure.
                std::cerr << "CRITICAL WORKER ERROR: " << e.what() << std::endl;
                break; // Stop the RUNNING loop, thread terminates
            }
        }
    }