Commit 8c868848 authored by jan.koester's avatar jan.koester
Browse files

ping fix

parent b7711b17
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -558,12 +558,21 @@ bool libhttppp::HttpEvent::Http2RequestEvent(netplus::con &curcon,

        case H2_FRAME_PING:
            // RFC 7540: respond only to non-ACK PING frames, payload must be 8 bytes.
            // Send PING ACK immediately via the socket so the peer doesn't
            // time out while a long-running RequestEvent is in progress.
            if (!(fflags & H2_FLAG_ACK) && flen == 8) {
                out += h2BuildFrame(H2_FRAME_PING, H2_FLAG_ACK, 0,
                std::string ping_ack = h2BuildFrame(H2_FRAME_PING, H2_FLAG_ACK, 0,
                                                    std::string(data + off, flen));
                if (!out.empty()) {
                    cureq.SendData.append(out.data(), out.size());
                    out.clear();
                if (cureq.csock) {
                    netplus::buffer buf(ping_ack.data(), ping_ack.size());
                    try {
                        cureq.csock->sendData(buf, 0);
                    } catch (...) {
                        // Fall back to buffered send if immediate write fails
                        out += ping_ack;
                    }
                } else {
                    out += ping_ack;
                }
            }
            break;