diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 50829c514ed..73ab8b4e457 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -683,6 +683,19 @@ int tcp_bind(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr); int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr); +/**************************************************************************** + * Name: tcp_removeconn + * + * Description: + * remove the connection from the list of active TCP connections + * + * Assumptions: + * This function is called from network logic with the network locked. + * + ****************************************************************************/ + +void tcp_removeconn(FAR struct tcp_conn_s *conn); + /**************************************************************************** * Name: psock_tcp_connect * diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 07676313d08..56e167eca07 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -1476,4 +1476,22 @@ errout_with_lock: return ret; } +/**************************************************************************** + * Name: tcp_removeconn + * + * Description: + * remove the connection from the list of active TCP connections + * + * Assumptions: + * This function is called from network logic with the network locked. + * + ****************************************************************************/ + +void tcp_removeconn(FAR struct tcp_conn_s *conn) +{ + net_lock(); + dq_rem(&conn->sconn.node, &g_active_tcp_connections); + net_unlock(); +} + #endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/net/tcp/tcp_connect.c b/net/tcp/tcp_connect.c index 45a5594a349..750d3875b7d 100644 --- a/net/tcp/tcp_connect.c +++ b/net/tcp/tcp_connect.c @@ -241,6 +241,12 @@ static uint16_t psock_connect_eventhandler(FAR struct net_driver_s *dev, ninfo("Resuming: %d\n", pstate->tc_result); + if (pstate->tc_result != OK) + { + tcp_removeconn(conn); + conn->tcpstateflags = TCP_ALLOCATED; + } + /* Stop further callbacks */ psock_teardown_callbacks(pstate, pstate->tc_result);