[lwip-devel] lwip does not use timeval structure and MEMP_MEM_MALLOC iss
From:
Midnight Xiong
Subject:
[lwip-devel] lwip does not use timeval structure and MEMP_MEM_MALLOC issue
Date:
Thu, 20 May 2010 23:03:40 +0800
Hi, (Please pardon me, I have no account in savannah) #1 SO_RCVTIMEO issue in setsockopt() function. In LwIP, it will support setsockopt() function for SO_RCVTIMEO. In BSD socket, it need a struct timeval *optval argurment. If the system has no struct timeval definition, this structure is provided in sockets.h file. However, in LwIP implementation, it's a msecond number.
#2, TCP pcb issue In some small RAM system, lwip can use none-memory pool method and use MEMP_MEM_MALLOC macro to replace memp_malloc with mem_malloc. However, the state of TCP connection will change to TIME_WAIT when TCP connection is disconnected. If there are lots of TCP connection and then disconnect sometime, there are most TIME_WAIT TCP pcb in the system and exhaust all of system memory. To fix this issue, following is a patch:
LWIP_DEBUGF(MEMP_DEBUG, ("memp free %s, mem 0x%x\n", memp_desc[type], mem)); /* release this memory */ mem_free(mem); #endif /* MEMP_MEM_MALLOC */ }
In this patch, a static variable tcp_pcbs is introduced to record the maximum allocated TCP pcb. If the allocated TCP pcb number is great than the system setting, NULL will be returned. According to lwip implementaion, if the return of memp_malloc for TCP pcb allocation is NULL, it will use some one in TIME_WAIT TCP pcb.