You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/01/30 03:25:42 UTC
[nuttx] branch master updated: free TCP rx buffer immediately in tcp_close
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b33474cb11 free TCP rx buffer immediately in tcp_close
b33474cb11 is described below
commit b33474cb1119b6c79b2aea0e19cc7eb9cbfdc687
Author: 梁超众 <li...@xiaomi.com>
AuthorDate: Tue Jan 3 20:16:07 2023 +0800
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: 梁超众 <li...@xiaomi.com>
Signed-off-by: chao an <an...@xiaomi.com>
---
net/tcp/tcp.h | 10 ++++++++++
net/tcp/tcp_close.c | 4 ++++
net/tcp/tcp_conn.c | 53 +++++++++++++++++++++++++++++++++--------------------
3 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h
index 62dfa05e9f..188e46c2b8 100644
--- a/net/tcp/tcp.h
+++ b/net/tcp/tcp.h
@@ -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
*
diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c
index 63afbe767e..3f1eb46ae2 100644
--- a/net/tcp/tcp_close.c
+++ b/net/tcp/tcp_close.c
@@ -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 |
diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index 487ab0829b..28b2d9c749 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -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 */