mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 06:39:01 +08:00
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:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user