From e469f2dea4f473e683ba1924a32ec2ac2b046b85 Mon Sep 17 00:00:00 2001 From: iosabi Date: Sat, 10 Apr 2021 18:45:57 +0200 Subject: [PATCH] lwip_sock: Make sock_tcp_read return data if available When reading from the socket with `sock_tcp_read()` it would only return data from at most one internal connection buffer, even if the buffer passed to `sock_tcp_read()` is larger and there is more data available in the connection. This patch makes `sock_tcp_read` process all the available data so long as there's more data to read available immediately. --- pkg/lwip/contrib/sock/tcp/lwip_sock_tcp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/lwip/contrib/sock/tcp/lwip_sock_tcp.c b/pkg/lwip/contrib/sock/tcp/lwip_sock_tcp.c index 36a4146e65..e07822d75f 100644 --- a/pkg/lwip/contrib/sock/tcp/lwip_sock_tcp.c +++ b/pkg/lwip/contrib/sock/tcp/lwip_sock_tcp.c @@ -353,7 +353,12 @@ ssize_t sock_tcp_read(sock_tcp_t *sock, void *data, size_t max_len, sock->last_buf = NULL; sock->last_offset = 0; pbuf_free(buf); - break; + /* Exit the loop only when there's no more data available in the + * connection. This allows to copy more data in a single read if + * available. */ + if (!mbox_avail(&sock->base.conn->recvmbox.mbox)) { + break; + } } } if (offset > 0) {