From 2919001e3ee681dfd906d432f7f6823458db11b1 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 Change-Id: Iace9ccfc73086db442db04b95bc508dd48827b82 Signed-off-by: chao.an --- net/socket/net_dup2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c index 4ff03637e5d..140da6d120f 100644 --- a/net/socket/net_dup2.c +++ b/net/socket/net_dup2.c @@ -46,6 +46,7 @@ #include #include +#include #include "inet/inet.h" #include "tcp/tcp.h" @@ -74,6 +75,7 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) { + FAR struct tcp_conn_s *conn; int ret = OK; /* Parts of this operation need to be atomic */ @@ -112,7 +114,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);