mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
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:
@@ -449,6 +449,16 @@ void tcp_initialize(void);
|
|||||||
|
|
||||||
FAR struct tcp_conn_s *tcp_alloc(uint8_t domain);
|
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
|
* Name: tcp_free
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -236,6 +236,10 @@ static inline int tcp_close_disconnect(FAR struct socket *psock)
|
|||||||
conn->tcpstateflags == TCP_LAST_ACK) &&
|
conn->tcpstateflags == TCP_LAST_ACK) &&
|
||||||
(conn->clscb = tcp_callback_alloc(conn)) != NULL)
|
(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 */
|
/* Set up to receive TCP data event callbacks */
|
||||||
|
|
||||||
conn->clscb->flags = TCP_NEWDATA | TCP_ACKDATA |
|
conn->clscb->flags = TCP_NEWDATA | TCP_ACKDATA |
|
||||||
|
|||||||
+33
-20
@@ -746,6 +746,38 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
|
|||||||
return conn;
|
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
|
* 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);
|
dq_rem(&conn->sconn.node, &g_active_tcp_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release any read-ahead buffers attached to the connection */
|
tcp_free_rx_buffers(conn);
|
||||||
|
|
||||||
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 */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||||
/* Release any write buffers attached to the connection */
|
/* Release any write buffers attached to the connection */
|
||||||
|
|||||||
Reference in New Issue
Block a user