|
33 | 33 | #else |
34 | 34 | #define GET_MAX_BLOCK_SIZE getMaxAllocHeap |
35 | 35 | #endif |
| 36 | +// When looking up available memory, leave some slack |
| 37 | +#define BLOCK_SIZE_SLACK 128 |
36 | 38 |
|
37 | 39 | // Since ESP8266 does not link memchr by default, here's its implementation. |
38 | 40 | void* memchr(void* ptr, int ch, size_t count) |
@@ -358,29 +360,25 @@ size_t AsyncAbstractResponse::_ack(AsyncWebServerRequest *request, size_t len, u |
358 | 360 | } else { |
359 | 361 | outLen = std::min(space, _contentLength - _sentLength); |
360 | 362 | } |
361 | | -#ifdef ESP8266 |
| 363 | + |
362 | 364 | // Limit outlen based on available memory |
363 | 365 | // We require two packet buffers - one allocated here, and one belonging to the TCP stack |
364 | 366 | { |
365 | 367 | auto old_space = _packet.capacity(); |
366 | | - auto max_block_size = ESP.getMaxFreeBlockSize() - 128; |
| 368 | + auto max_block_size = ESP.GET_MAX_BLOCK_SIZE() - BLOCK_SIZE_SLACK; |
367 | 369 | if ((old_space < outLen) || (outLen > max_block_size)) { |
368 | 370 | DEBUG_PRINTFP("(%d) Space adjustment, have %d, want %d, avail %d\n", (intptr_t)this, old_space, outLen, max_block_size); |
369 | 371 | do { |
370 | 372 | dealloc_vector(_packet); |
371 | 373 | outLen = std::min(outLen, max_block_size); |
372 | 374 | _packet.reallocate(outLen); |
373 | | - max_block_size = ESP.getMaxFreeBlockSize() - 128; |
| 375 | + max_block_size = ESP.GET_MAX_BLOCK_SIZE() - BLOCK_SIZE_SLACK; |
374 | 376 | DEBUG_PRINTFP("(%d) Checking %d vs %d\n", (intptr_t)this, outLen, max_block_size); |
375 | 377 | } while (max_block_size < outLen); |
376 | 378 | } else { |
377 | 379 | _packet.reallocate(outLen); |
378 | 380 | } |
379 | 381 | } |
380 | | -#else |
381 | | - //Serial.printf("[%u] %d/%d -> %d\n", (unsigned) millis(), ESP.getMaxAllocHeap(), ESP.getFreeHeap(), outLen); |
382 | | - _packet.reallocate(outLen); |
383 | | -#endif |
384 | 382 |
|
385 | 383 | if(_chunked){ |
386 | 384 | // HTTP 1.1 allows leading zeros in chunk length. Or spaces may be added. |
|
0 commit comments