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

epoll/kqueue arm guards for pre-handshake send data

parent 223c9f05
Loading
Loading
Loading
Loading
+9 −2
Changes for src/event/epoll.cpp: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -114,8 +114,15 @@ namespace netplus {

            int next = EPOLLRDHUP | EPOLLIN | EPOLLONESHOT;

            // Check if we have pending writes
            if (_con->SendData.pos < _con->SendData.size() || _con->slots[0].csock->hasPendingWrite()
            // Check if we have pending writes. Application data queued before a TLS
            // handshake finished (e.g. an IMAPS/SMTPS greeting written in ConnectEvent)
            // can't be sent yet -- sendData() throws Note until then -- so it must not
            // arm EPOLLOUT: the socket is writable the whole time, which would spin a
            // worker until the peer's next handshake flight arrives. It goes out in the
            // same IoEventHandler pass that completes the handshake (Step 4).
            bool appDataSendable = _con->SendData.pos < _con->SendData.size()
                                && _con->slots[0].csock->getHandshakeDone();
            if (appDataSendable || _con->slots[0].csock->hasPendingWrite()
                || _con->slots[0].ResponsePending.exchange(false, std::memory_order_acq_rel))
                next |= EPOLLOUT;

+6 −1
Changes for src/event/kqueue.cpp: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -184,7 +184,12 @@ namespace netplus {
            try {
                if (!_con->slots[0].csock) return;

                bool needWrite = _con->SendData.pos < _con->SendData.size()
                // Application data queued before the TLS handshake finished can't be
                // sent yet (see EpollArmGuard in epoll.cpp): arming WRITE for it would
                // spin until the peer's next handshake flight, and -- since WRITE is
                // armed *instead of* READ here -- delay reading that flight too.
                bool needWrite = (_con->SendData.pos < _con->SendData.size()
                                  && _con->slots[0].csock->getHandshakeDone())
                              || _con->slots[0].csock->hasPendingWrite()
                              || _con->slots[0].ResponsePending.exchange(false, std::memory_order_relaxed);