xiaoxiang781216 commented on code in PR #7525: URL: https://github.com/apache/nuttx/pull/7525#discussion_r1045191991
########## net/tcp/tcp_conn.c: ########## @@ -549,16 +549,25 @@ FAR struct tcp_conn_s *tcp_alloc_conn(void) if (dq_peek(&g_free_tcp_connections) == NULL) { +#if CONFIG_NET_TCP_MAX_CONNS > 0 + if (dq_count(&g_active_tcp_connections) + CONFIG_NET_TCP_ALLOC_CONNS Review Comment: ```suggestion if (dq_count(&g_active_tcp_connections) + CONFIG_NET_TCP_PREALLOC_CONNS ``` ########## include/nuttx/net/netconfig.h: ########## @@ -456,11 +456,11 @@ * connection requires approximately 30 bytes of memory. */ -#ifndef CONFIG_NET_TCP_CONNS -# ifdef CONFIG_NET_TCP -# define CONFIG_NET_TCP_CONNS 10 +#ifndef CONFIG_NET_TCP_PREALLOC_CONNS Review Comment: should we simply remove line 450-466? ########## net/tcp/tcp_conn.c: ########## @@ -699,9 +717,10 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) /* Allocate the connect entry from heap */ -#ifdef CONFIG_NET_ALLOC_CONNS +#if CONFIG_NET_TCP_ALLOC_CONNS > 0 if (conn == NULL) { + alloc_conn = 1; Review Comment: the allocation check is wrong since the free connection got above may dynamically allocate too, but put to the free list in tcp_free. ########## net/tcp/tcp_conn.c: ########## @@ -836,10 +862,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); + + /* If this is a preallocated or a batch allocated connection store it in + * the free connections list. Else free it. + */ + +#if CONFIG_NET_TCP_ALLOC_CONNS == 1 + if ((conn->flags & TCP_PREALLOC) == 0) Review Comment: there is a simple method to know this conn come from global variable by: ``` conn >= g_tcp_connections && conn < g_tcp_connections + CONFIG_NET_TCP_PREALLOC_CONNS ``` ########## net/tcp/Kconfig: ########## @@ -51,11 +51,45 @@ config NET_TCPURGDATA compiled in. Urgent data (out-of-band data) is a rarely used TCP feature that is very seldom would be required. -config NET_TCP_CONNS - int "Number of TCP/IP connections" +config NET_TCP_PREALLOC_CONNS + int "Preallocated TCP/IP connections" default 8 ---help--- - Maximum number of TCP/IP connections (all tasks) + Number of TCP/IP connections (all tasks). + + This number of connections will be pre-allocated during system boot. + If dynamic connections allocation is enabled, more connections may + be allocated at a later time, as the system needs them. Else this + will be the maximum number of connections available to the system + at all times. + + Set to 0 to disable (and rely only on dynamic allocations). + +config NET_TCP_ALLOC_CONNS + int "Dynamic TCP/IP connections allocation" + default 0 Review Comment: ```suggestion default NET_TCP_PREALLOC_CONNS ``` -- 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