Unverified Commit 8fd56ada authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Adjust tcp_write size when memory is tight (#729)

Increases the MEM_SIZE outstanding write buffer to 8K

Allows the ClientContext to attempt to send smaller buffer chunks in the
case where MEM_SIZE won't allow the full tcp_sndbuf() transfer.

Fixes #725
parent 5ab19e9a
......@@ -21,7 +21,7 @@ extern void interrupts();
#define MEM_LIBC_MALLOC 0
#define MEM_ALIGNMENT 4
#define MEM_SIZE 4000
#define MEM_SIZE 8192
#define MEMP_NUM_TCP_SEG 32
#define MEMP_NUM_ARP_QUEUE 10
#define PBUF_POOL_SIZE 24
......
No preview for this file type
No preview for this file type
......@@ -491,6 +491,7 @@ protected:
DEBUGV(":wr %d %d\r\n", _datalen - _written, _written);
bool has_written = false;
int scale = 0;
while (_written < _datalen) {
if (state() == CLOSED) {
......@@ -501,6 +502,10 @@ protected:
{
LWIPMutex m; // Block the timer sys_check_timeouts call, just for this call
next_chunk_size = std::min((size_t)tcp_sndbuf(_pcb), remaining);
// Potentially reduce transmit size if we are tight on memory, but only if it doesn't return a 0 chunk size
if (next_chunk_size > (size_t)(1 << scale)) {
next_chunk_size >>= scale;
}
}
if (!next_chunk_size) {
break;
......@@ -531,6 +536,13 @@ protected:
if (err == ERR_OK) {
_written += next_chunk_size;
has_written = true;
} else if (err == ERR_MEM) {
if (scale < 4) {
// Retry sending at 1/2 the chunk size
scale ++;
} else {
break;
}
} else {
// ERR_MEM(-1) is a valid error meaning
// "come back later". It leaves state() opened
......
......@@ -21,7 +21,7 @@ extern void interrupts();
#define MEM_LIBC_MALLOC 0
#define MEM_ALIGNMENT 4
#define MEM_SIZE 4000
#define MEM_SIZE 8192
#define MEMP_NUM_TCP_SEG 32
#define MEMP_NUM_ARP_QUEUE 10
#define PBUF_POOL_SIZE 24
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment