Commit 5314fe34 authored by jan.koester's avatar jan.koester
Browse files

test

parent a73d79ed
Loading
Loading
Loading
Loading
+42 −2
Changes for src/event/epoll.cpp: 42 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -93,8 +93,48 @@ namespace netplus {
        int _Timeout;
    };

    // Level-triggered epoll no longer requires re-arming
    // (EPOLLONESHOT eliminated for better performance)
    // RAII Rearm (EPOLLONESHOT) - more efficient than level-triggered
    // Since we batch send operations, re-arming syscalls are amortized
    class EpollArmGuard {
    public:
        EpollArmGuard(int fd, std::shared_ptr<con> c, pollapi* pptr)
            : _fd(fd), _con(std::move(c)), _pptr(pptr) {}

        ~EpollArmGuard() {
            if (!_armed) return;
            if (!_con || !_con->csock) return;

            int next = EPOLLRDHUP | EPOLLONESHOT;

            // during handshake => need IN, and OUT only if pending writes
            if (!_con->csock->getHandshakeDone()) {
                next |= EPOLLIN;
                if (_con->csock->hasPendingWrite())
                    next |= EPOLLOUT;
            } else {
                next |= EPOLLIN;
                if (_con->SendData.pos < _con->SendData.size() || _con->csock->hasPendingWrite())
                    next |= EPOLLOUT;
                // If TLS has buffered data, trigger EPOLLOUT to force a wakeup
                if (_con->csock->hasBufferedData())
                    next |= EPOLLOUT;
            }

            try {
                _pptr->setpollEventsFd(_fd, next);
            } catch (...) {
                // ignore
            }
        }

        void disarm() { _armed = false; }

    private:
        bool _armed = true;
        int _fd;
        std::shared_ptr<con> _con;
        pollapi* _pptr;
    };

    // ------------------------------------------------------------
    // poll implementation