Fix broken MSG_PEEK on TCP sockets (post-2.0.3 bug)

MSG_PEEK on TCP sockets was broken since commit b71d4477ea
from 06.03.2017: recv hung in an endless loop and tcp_recved() was called for peeked data
(which would result in a too large window advertised).

Aded TCP MSG_PEEK to socket unit tests
This commit is contained in:
goldsimon 2017-11-18 13:34:20 +01:00
parent d99144eef1
commit f5c37c8cbb
2 changed files with 8 additions and 2 deletions

View File

@ -926,9 +926,9 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags)
/* once we have some data to return, only add more if we don't need to wait */
apiflags |= NETCONN_DONTBLOCK;
/* @todo: do we need to support peeking more than one pbuf? */
} while ((recv_left > 0) || (flags & MSG_PEEK));
} while ((recv_left > 0) && !(flags & MSG_PEEK));
lwip_recv_tcp_done:
if (recvd > 0) {
if ((recvd > 0) && !(flags & MSG_PEEK)) {
/* ensure window update after copying all data */
netconn_tcp_recvd(sock->conn, (size_t)recvd);
}

View File

@ -161,6 +161,12 @@ static void test_sockets_allfunctions_basic_domain(int domain)
while(tcpip_thread_poll_one());
ret = lwip_recv(s2, buf, 3, MSG_PEEK);
fail_unless(ret == 3);
ret = lwip_recv(s2, buf, 3, MSG_PEEK);
fail_unless(ret == 3);
ret = lwip_read(s2, buf, 4);
fail_unless(ret == 4);