xiaoxiang781216 commented on code in PR #7525: URL: https://github.com/apache/nuttx/pull/7525#discussion_r1032793402
########## net/tcp/tcp_conn.c: ########## @@ -586,16 +586,32 @@ FAR struct tcp_conn_s *tcp_alloc_conn(void) void tcp_initialize(void) { -#ifndef CONFIG_NET_ALLOC_CONNS int i; +#ifndef CONFIG_NET_ALLOC_CONNS for (i = 0; i < CONFIG_NET_TCP_CONNS; i++) { /* Mark the connection closed and move it to the free list */ g_tcp_connections[i].tcpstateflags = TCP_CLOSED; dq_addlast(&g_tcp_connections[i].sconn.node, &g_free_tcp_connections); } +#else + FAR struct tcp_conn_s *conn; + + for (i = 0; i < CONFIG_NET_TCP_PREALLOC_CONNS; i++) + { + conn = kmm_zalloc(sizeof(struct tcp_conn_s)); Review Comment: why not reuse g_tcp_connections? ########## include/nuttx/net/netconfig.h: ########## @@ -457,7 +457,7 @@ */ #ifndef CONFIG_NET_TCP_CONNS -# ifdef CONFIG_NET_TCP +# if defined CONFIG_NET_TCP && !defined CONFIG_NET_ALLOC_CONNS Review Comment: ```suggestion # if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_ALLOC_CONNS) ``` ########## net/tcp/tcp_conn.c: ########## @@ -836,10 +865,25 @@ void tcp_free(FAR struct tcp_conn_s *conn) } #endif - /* Mark the connection available and put it into the free list */ + /* Mark the connection available. */ conn->tcpstateflags = TCP_CLOSED; - dq_addlast(&conn->sconn.node, &g_free_tcp_connections); + + /* Check if this is a preallocated connection to store it in the free + * connections list, else deallocate it. + */ + +#ifdef CONFIG_NET_ALLOC_CONNS + if ((conn->flags & TCP_PREALLOC) == 0) + { + free(conn); Review Comment: kmm_free -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org