net/tcp:resolve reconnection issues when connection failed due to rejection

After first connection refused happend,The user use the same connection failed,becasue the tcpstateflags is not TCP_ALLOCATED

Signed-off-by: wangchen <wangchen41@xiaomi.com>
This commit is contained in:
wangchen
2024-10-26 17:13:03 +08:00
committed by Xiang Xiao
parent aba8cd4d86
commit f10fc888fe
3 changed files with 37 additions and 0 deletions
+13
View File
@@ -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
*
+18
View File
@@ -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 */
+6
View File
@@ -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);