diff options
Diffstat (limited to 'tests/auto/network/access/http2/http2srv.cpp')
-rw-r--r-- | tests/auto/network/access/http2/http2srv.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/tests/auto/network/access/http2/http2srv.cpp b/tests/auto/network/access/http2/http2srv.cpp index b0bae13bad..1f9ffb8985 100644 --- a/tests/auto/network/access/http2/http2srv.cpp +++ b/tests/auto/network/access/http2/http2srv.cpp @@ -212,13 +212,30 @@ void Http2Server::sendDATA(quint32 streamID, quint32 windowSize) const quint32 offset = it->second; Q_ASSERT(offset < quint32(responseBody.size())); - const quint32 bytes = std::min<quint32>(windowSize, responseBody.size() - offset); + quint32 bytesToSend = std::min<quint32>(windowSize, responseBody.size() - offset); + quint32 bytesSent = 0; const quint32 frameSizeLimit(clientSetting(Settings::MAX_FRAME_SIZE_ID, Http2::maxFrameSize)); const uchar *src = reinterpret_cast<const uchar *>(responseBody.constData() + offset); - const bool last = offset + bytes == quint32(responseBody.size()); + const bool last = offset + bytesToSend == quint32(responseBody.size()); + + // The payload can significantly exceed frameSizeLimit. Internally, writer + // will do needed fragmentation, but if some test failed, there is no need + // to wait for writer to send all DATA frames, we check 'interrupted' and + // stop early instead. + const quint32 framesInChunk = 10; + while (bytesToSend) { + if (interrupted.loadAcquire()) + return; + const quint32 chunkSize = std::min<quint32>(framesInChunk * frameSizeLimit, bytesToSend); + writer.start(FrameType::DATA, FrameFlag::EMPTY, streamID); + writer.writeDATA(*socket, frameSizeLimit, src, chunkSize); + src += chunkSize; + bytesToSend -= chunkSize; + bytesSent += chunkSize; + } - writer.start(FrameType::DATA, FrameFlag::EMPTY, streamID); - writer.writeDATA(*socket, frameSizeLimit, src, bytes); + if (interrupted.loadAcquire()) + return; if (last) { writer.start(FrameType::DATA, FrameFlag::END_STREAM, streamID); @@ -230,7 +247,7 @@ void Http2Server::sendDATA(quint32 streamID, quint32 windowSize) Q_ASSERT(closedStreams.find(streamID) == closedStreams.end()); closedStreams.insert(streamID); } else { - it->second += bytes; + it->second += bytesSent; } } @@ -819,6 +836,11 @@ void Http2Server::sendResponse(quint32 streamID, bool emptyBody) } } +void Http2Server::stopSendingDATAFrames() +{ + interrupted.storeRelease(1); +} + void Http2Server::processRequest() { Q_ASSERT(continuedRequest.size()); |