Skip to content

Commit 0d73dd8

Browse files
committed
AsyncAbstractResponse::_ack: Additional debugging
Provide some indication of partial buffer writes
1 parent b513859 commit 0d73dd8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/WebResponses.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ size_t AsyncAbstractResponse::_ack(AsyncWebServerRequest *request, size_t len, u
310310
size_t space = request->client()->space(); // TCP window space available; NOT a guarantee we can actually send this much
311311
size_t headLen = _head.length();
312312
bool needs_send = false;
313+
if ((space == 0) && ((_state == RESPONSE_HEADERS) || (_state == RESPONSE_CONTENT))) {
314+
// Cannot accept more data now, wait for next event
315+
DEBUG_PRINTFP("(%d) No space to write\n", (intptr_t)this);
316+
return 0;
317+
}
313318

314319
if(_state == RESPONSE_HEADERS){
315320
auto headWritten = request->client()->add(_head.c_str(), std::min(space, headLen));
@@ -334,7 +339,8 @@ size_t AsyncAbstractResponse::_ack(AsyncWebServerRequest *request, size_t len, u
334339
space -= written;
335340
if (_packet.size()) {
336341
// Couldn't queue the full cache
337-
request->client()->send();
342+
DEBUG_PRINTFP("(%d) Partial buffered write: wrote %d, remaining %d\n", (intptr_t)this, written, _packet.size());
343+
if (written) request->client()->send();
338344
return written;
339345
}
340346
needs_send = true;

0 commit comments

Comments
 (0)