Skip to content

Commit 646c41d

Browse files
zhhyu7pkarashchenko
authored andcommitted
tcp_monitor: start_monitor return OK when connect closed by peer
If TCP_FIN is received before the user calls accept, the later accept will report an error, then the previously received data cannot be read. operation flow: tcp_server_listen -> tcp_client_connect -> tcp_client_send -> tcp_client_close -> tcp_server_accept(fix this error) -> tcp_server_recv Signed-off-by: zhanghongyu <[email protected]>
1 parent f7cfcd4 commit 646c41d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

net/tcp/tcp_monitor.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ int tcp_start_monitor(FAR struct socket *psock)
271271

272272
tcp_shutdown_monitor(conn, TCP_CLOSE);
273273

274+
/* If the peer close the connection before we call accept,
275+
* in order to allow user to read the readahead data,
276+
* return OK.
277+
*/
278+
279+
if (conn->tcpstateflags == TCP_CLOSED ||
280+
conn->tcpstateflags == TCP_LAST_ACK)
281+
{
282+
net_unlock();
283+
return OK;
284+
}
285+
274286
/* And return -ENOTCONN to indicate the monitor was not started
275287
* because the socket was already disconnected.
276288
*/

0 commit comments

Comments
 (0)