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 <anchao@xiaomi.com>
This commit is contained in:
parent
6f14299dd0
commit
60407c8c8a
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user