net/tcp: fix tcp socket close timeout if loss wireless connection

In the current net stack implementation, there is no mechanism
for notifying the loss of the wireless connection, if the network
is disconnected then application sends data packets through tcp,
the tcp_timer will keep retrying fetch the ack for awhile, the
connection status will not be able to be switched timely.

Change-Id: I84d1121527edafc6ee6ad56ba164838694e7e11c
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2020-08-07 17:32:55 +08:00 committed by Xiang Xiao
parent 1e321ca032
commit d78bf36740
2 changed files with 16 additions and 2 deletions

View File

@ -105,6 +105,11 @@ int netdev_carrier_off(FAR struct net_driver_s *dev)
{
dev->d_flags &= ~IFF_RUNNING;
netlink_device_notify(dev);
/* Notify clients that the network has been taken down */
devif_dev_event(dev, NULL, NETDEV_DOWN);
return OK;
}

View File

@ -205,7 +205,8 @@ static void psock_writebuffer_notify(FAR struct tcp_conn_s *conn)
****************************************************************************/
static inline void psock_lost_connection(FAR struct socket *psock,
FAR struct tcp_conn_s *conn)
FAR struct tcp_conn_s *conn,
bool abort)
{
FAR sq_entry_t *entry;
FAR sq_entry_t *next;
@ -245,6 +246,14 @@ static inline void psock_lost_connection(FAR struct socket *psock,
conn->sent = 0;
conn->sndseq_max = 0;
/* Force abort the connection. */
if (abort)
{
conn->tx_unacked = 0;
conn->tcpstateflags = TCP_CLOSED;
}
}
}
@ -503,7 +512,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
/* Free write buffers and terminate polling */
psock_lost_connection(psock, conn);
psock_lost_connection(psock, conn, !!(flags & NETDEV_DOWN));
return flags;
}