You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/03/19 08:23:26 UTC
[incubator-nuttx] branch master updated: net/tcp: do not start the
tcp monitor if unestablished
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 60407c8 net/tcp: do not start the tcp monitor if unestablished
60407c8 is described below
commit 60407c8c8ac6679094691dc3f358db8934b37a39
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Mar 18 23:30:40 2021 +0800
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 <an...@xiaomi.com>
---
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 05598bb..ff765b4 100644
--- a/net/socket/net_dup2.c
+++ b/net/socket/net_dup2.c
@@ -31,6 +31,7 @@
#include <debug.h>
#include <nuttx/net/net.h>
+#include <nuttx/net/tcp.h>
#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);