Commit 58660cdf authored by jan.koester's avatar jan.koester
Browse files

httpclient can wait

parent 3ca63e99
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -686,6 +686,11 @@ bool libhttppp::HttpClient::isStreaming() const {
    return _streamMode != STREAM_NONE;
}

bool libhttppp::HttpClient::waitReadable(int timeout_ms) {
    if (!_cltsock) return false;
    return _sw.waitRead(*_cltsock, timeout_ms);
}

libhttppp::HttpResponse libhttppp::HttpClient::GetStream(libhttppp::HttpRequest &nreq) {
    try {
        _ensureConnected();
+5 −0
Original line number Diff line number Diff line
@@ -109,6 +109,11 @@ namespace libhttppp {
      // True while a streaming read is in progress.
      bool isStreaming() const;

      // Wait until upstream socket has data to read (or timeout expires).
      // timeout_ms: -1 = infinite, 0 = return immediately, >0 = milliseconds
      // Returns true if readable, false on timeout.
      bool waitReadable(int timeout_ms);

      // Shared TLS session cache — enables abbreviated TLS 1.2 handshakes
      // across reconnects to the same host.  One cache per process.
      static netplus::TlsSessionCache& tlsSessionCache();
+5 −2
Original line number Diff line number Diff line
@@ -420,6 +420,7 @@ void libhttppp::HttpEvent::_dispatchH2Stream(HttpRequest &cureq,

            size_t max_iterations = content_length / BLOCKSIZE + 4096;
            size_t empty_count = 0;
            unsigned int backoff_ms = 1;
            for (size_t i = 0;
                 i < max_iterations && body.size() < content_length;
                 ++i) {
@@ -429,13 +430,15 @@ void libhttppp::HttpEvent::_dispatchH2Stream(HttpRequest &cureq,
                    body.append(tempreq.SendData.data(), sa);
                    tempreq.SendData.clear();
                    empty_count = 0;
                    backoff_ms = 1;
                } else {
                    ++empty_count;
                    if (empty_count > 500) {
                        break; // Genuine stall — give up
                    }
                    // No data yet — yield briefly so backend can deliver
                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
                    // No data yet — exponential backoff to reduce CPU usage
                    std::this_thread::sleep_for(std::chrono::milliseconds(backoff_ms));
                    if (backoff_ms < 32) backoff_ms *= 2;
                }
            }
        }