From 48f6990fbc54ac29b15fa765d431244d1dcb5f21 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 31 Oct 2017 13:50:08 +1100 Subject: [PATCH] extmod/modlwip: Commit TCP out data to lower layers if buffer gets full. Dramatically improves TCP sending throughput because without an explicit call to tcp_output() the data is only sent to the lower layers via the lwIP slow timer which (by default) ticks every 500ms. --- extmod/modlwip.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index bbb01b5d7..2c194e1bd 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -498,6 +498,11 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui err_t err = tcp_write(socket->pcb.tcp, buf, write_len, TCP_WRITE_FLAG_COPY); + // If the output buffer is getting full then send the data to the lower layers + if (err == ERR_OK && tcp_sndbuf(socket->pcb.tcp) < TCP_SND_BUF / 4) { + err = tcp_output(socket->pcb.tcp); + } + if (err != ERR_OK) { *_errno = error_lookup_table[-err]; return MP_STREAM_ERROR;