From 60407c8c8ac6679094691dc3f358db8934b37a39 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Thu, 18 Mar 2021 23:30:40 +0800 Subject: [PATCH] net/tcp: do not start the tcp monitor if unestablished Add more sanity checks to avoid TCP moniter start fail if the TCP handle unestablished, the dup(2) operation should work at any time Signed-off-by: chao.an --- net/socket/net_dup2.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c index 05598bb6a7e..ff765b481ed 100644 --- a/net/socket/net_dup2.c +++ b/net/socket/net_dup2.c @@ -31,6 +31,7 @@ #include #include +#include #include "inet/inet.h" #include "tcp/tcp.h" @@ -59,6 +60,9 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) { +#ifdef NET_TCP_HAVE_STACK + FAR struct tcp_conn_s *conn; +#endif int ret = OK; /* Parts of this operation need to be atomic */ @@ -97,7 +101,11 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) * the network connection is lost. */ - if (psock2->s_type == SOCK_STREAM) + conn = (FAR struct tcp_conn_s *)psock2->s_conn; + + if (psock2->s_type == SOCK_STREAM && conn && + (conn->tcpstateflags == TCP_ESTABLISHED || + conn->tcpstateflags == TCP_SYN_RCVD)) { ret = tcp_start_monitor(psock2);