diff --git a/net/tcp/tcp_monitor.c b/net/tcp/tcp_monitor.c index ec4cbf613e..5c620f4045 100644 --- a/net/tcp/tcp_monitor.c +++ b/net/tcp/tcp_monitor.c @@ -271,6 +271,18 @@ int tcp_start_monitor(FAR struct socket *psock) tcp_shutdown_monitor(conn, TCP_CLOSE); + /* If the peer close the connection before we call accept, + * in order to allow user to read the readahead data, + * return OK. + */ + + if (conn->tcpstateflags == TCP_CLOSED || + conn->tcpstateflags == TCP_LAST_ACK) + { + net_unlock(); + return OK; + } + /* And return -ENOTCONN to indicate the monitor was not started * because the socket was already disconnected. */