From b34f2d5605d37f26aed2553d8235896826a240c1 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 5 Apr 2017 12:17:15 +0200 Subject: [PATCH] altcp: allocate altcp_pcbs from a pool, not from heap (new option MEMP_NUM_ALTCP_PCB defaults to MEMP_NUM_TCP_PCB) --- src/core/altcp.c | 6 ++---- src/core/memp.c | 1 + src/include/lwip/opt.h | 10 ++++++++++ src/include/lwip/priv/memp_std.h | 4 ++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/altcp.c b/src/core/altcp.c index 0475828c..4e931f9e 100644 --- a/src/core/altcp.c +++ b/src/core/altcp.c @@ -59,8 +59,7 @@ extern const struct altcp_functions altcp_tcp_functions; struct altcp_pcb * altcp_alloc(void) { - /* FIXME: pool alloc */ - struct altcp_pcb *ret = (struct altcp_pcb *)mem_malloc(sizeof(struct altcp_pcb)); + struct altcp_pcb *ret = (struct altcp_pcb *)memp_malloc(MEMP_ALTCP_PCB); if (ret != NULL) { memset(ret, 0, sizeof(struct altcp_pcb)); } @@ -70,9 +69,8 @@ altcp_alloc(void) void altcp_free(struct altcp_pcb *conn) { - /* FIXME: pool alloc */ if (conn) { - mem_free(conn); + memp_free(MEMP_ALTCP_PCB, conn); } } diff --git a/src/core/memp.c b/src/core/memp.c index c7152730..515df2d6 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -57,6 +57,7 @@ #include "lwip/udp.h" #include "lwip/tcp.h" #include "lwip/priv/tcp_priv.h" +#include "lwip/altcp.h" #include "lwip/ip4_frag.h" #include "lwip/netbuf.h" #include "lwip/api.h" diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 8dee1f39..236ec0c3 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -399,6 +399,16 @@ #define MEMP_NUM_TCP_SEG 16 #endif +/** + * MEMP_NUM_ALTCP_PCB: the number of simultaneously active altcp layer pcbs. + * (requires the LWIP_ALTCP option) + * Connections with multiple layers require more than one altcp_pcb (e.g. TLS + * over TCP requires 2 altcp_pcbs, one for TLS and one for TCP). + */ +#if !defined MEMP_NUM_ALTCP_PCB || defined __DOXYGEN__ +#define MEMP_NUM_ALTCP_PCB MEMP_NUM_TCP_PCB +#endif + /** * MEMP_NUM_REASSDATA: the number of IP packets simultaneously queued for * reassembly (whole packets, not fragments!) diff --git a/src/include/lwip/priv/memp_std.h b/src/include/lwip/priv/memp_std.h index ce9fd500..e2e5fbbc 100644 --- a/src/include/lwip/priv/memp_std.h +++ b/src/include/lwip/priv/memp_std.h @@ -52,6 +52,10 @@ LWIP_MEMPOOL(TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN, sizeof(struct tcp_pcb_lis LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), "TCP_SEG") #endif /* LWIP_TCP */ +#if LWIP_ALTCP && LWIP_TCP +LWIP_MEMPOOL(ALTCP_PCB, MEMP_NUM_ALTCP_PCB, sizeof(struct altcp_pcb), "ALTCP_PCB") +#endif /* LWIP_ALTCP && LWIP_TCP */ + #if LWIP_IPV4 && IP_REASSEMBLY LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA") #endif /* LWIP_IPV4 && IP_REASSEMBLY */