free TCP rx buffer immediately in tcp_close

Issue:
TCP rx buffer is freed after 4-way handshake with current design.
3 socket's rx buffer might be consumed during ffmpeg switch music procedure,
and this might cause IOB exhausted.

Solution:
free TCP rx buffer immediately in tcp_close to make sure IOB won't be
exhausted.

Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
梁超众 2023-01-03 20:16:07 +08:00 committed by Xiang Xiao
parent 98e1f9c36d
commit b33474cb11
3 changed files with 47 additions and 20 deletions

View File

@ -449,6 +449,16 @@ void tcp_initialize(void);
FAR struct tcp_conn_s *tcp_alloc(uint8_t domain);
/****************************************************************************
* Name: tcp_free_rx_buffers
*
* Description:
* Free rx buffer of a connection
*
****************************************************************************/
void tcp_free_rx_buffers(FAR struct tcp_conn_s *conn);
/****************************************************************************
* Name: tcp_free
*

View File

@ -236,6 +236,10 @@ static inline int tcp_close_disconnect(FAR struct socket *psock)
conn->tcpstateflags == TCP_LAST_ACK) &&
(conn->clscb = tcp_callback_alloc(conn)) != NULL)
{
/* Free rx buffers of the connection immediately */
tcp_free_rx_buffers(conn);
/* Set up to receive TCP data event callbacks */
conn->clscb->flags = TCP_NEWDATA | TCP_ACKDATA |

View File

@ -746,6 +746,38 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
return conn;
}
/****************************************************************************
* Name: tcp_free_rx_buffers
*
* Description:
* Free rx buffer of a connection
*
****************************************************************************/
void tcp_free_rx_buffers(FAR struct tcp_conn_s *conn)
{
/* Release any read-ahead buffers attached to the connection */
iob_free_chain(conn->readahead);
conn->readahead = NULL;
#ifdef CONFIG_NET_TCP_OUT_OF_ORDER
/* Release any out-of-order buffers */
if (conn->nofosegs > 0)
{
int i;
for (i = 0; i < conn->nofosegs; i++)
{
iob_free_chain(conn->ofosegs[i].data);
}
conn->nofosegs = 0;
}
#endif /* CONFIG_NET_TCP_OUT_OF_ORDER */
}
/****************************************************************************
* Name: tcp_free
*
@ -801,26 +833,7 @@ void tcp_free(FAR struct tcp_conn_s *conn)
dq_rem(&conn->sconn.node, &g_active_tcp_connections);
}
/* Release any read-ahead buffers attached to the connection */
iob_free_chain(conn->readahead);
conn->readahead = NULL;
#ifdef CONFIG_NET_TCP_OUT_OF_ORDER
/* Release any out-of-order buffers */
if (conn->nofosegs > 0)
{
int i;
for (i = 0; i < conn->nofosegs; i++)
{
iob_free_chain(conn->ofosegs[i].data);
}
conn->nofosegs = 0;
}
#endif /* CONFIG_NET_TCP_OUT_OF_ORDER */
tcp_free_rx_buffers(conn);
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
/* Release any write buffers attached to the connection */