Commit 1e9789d6 authored by jan.koester's avatar jan.koester
Browse files

bugfix recvdata

parent 3d2b640c
Loading
Loading
Loading
Loading
+14 −0
Changes for src/http.cpp: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -461,6 +461,15 @@ void libhttppp::HttpClient::_ensureConnected() {
// Returns 0 on connection closure. Throws on hard errors.
// Hard timeout to prevent infinite hangs on silently-dead connections.
size_t libhttppp::HttpClient::_recvBlocking(netplus::buffer &b, int timeout_sec) {
    // tcp::recvData()/ssl::recvData() request up to b.size bytes and then
    // OVERWRITE b.size with however many actually arrived (see
    // libnetplus/src/posix/tcp.cpp). b is always _recvScratch, reused across
    // calls instead of freshly constructed -- without resetting b.size back
    // to its real capacity here, a single small read (common on the very
    // first TCP segment) would permanently shrink every subsequent request
    // on this object to that same small size, turning what used to be a few
    // 64KB reads into many tiny ones.
    b.size = CHUNKSIZE;
    if (timeout_sec <= 0)
        timeout_sec = _recvTimeoutSec;
    auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(timeout_sec);
@@ -487,6 +496,7 @@ size_t libhttppp::HttpClient::_recvNonBlocking(netplus::buffer &b) {
    if (!_cltsock) {
        return 0;
    }
    b.size = CHUNKSIZE; // see _recvBlocking() -- recvData() shrinks b.size to bytes read
    try {
        return _cltsock->recvData(b, 0);
    } catch (netplus::NetException &e) {
@@ -2412,6 +2422,9 @@ const std::vector<char> libhttppp::HttpClient::_h2Request(
        // Helper: blocking recv using socketwait::waitRead()
        auto recv_deadline = std::chrono::steady_clock::now() + std::chrono::seconds(60);
        auto recv_blocking = [&](netplus::buffer& b) -> size_t {
            // b is _recvScratch; recvData() shrinks b.size to bytes read, so
            // reset before every attempt (see _recvBlocking() for why).
            b.size = CHUNKSIZE;
            for (;;) {
                try {
                    return _cltsock->recvData(b, 0);
@@ -2579,6 +2592,7 @@ const std::vector<char> libhttppp::HttpClient::_h2Request(
            // Try a non-blocking read to pick up the server's SETTINGS
            // (which usually arrives right after TLS handshake).
            {
                _recvScratch.size = CHUNKSIZE; // see _recvBlocking() for why
                size_t n = 0;
                try { n = _cltsock->recvData(_recvScratch, 0); } catch (...) {}
                if (n > 0) {