Hi Jianwu,
Yes, you need to destroy the task since it won't be used any more for the closed socket.
The only stack consumed is the used by the task created to handle that connection.
With the TaskAwareDebugging, you can see that every new TCP socket connection needs extra 500+4392x2+148=9432B/59.0KB=16% as follows:
MQX -> Lightweight Memory Block Summary Size (Decimal) Owner Type
500 0x10001 TCP Control Block;RTCS/TCP
4392 0x10001 TCP Tx Window;RTCS/TCP
4392 0x10001 TCP Rx Window;RTCS/TCP
148 0x10001 TCP Send Clock;RTCS/TCP
(TCP/IP Task id is 0x10001)
The default OPT_TBSIZE and OPT_RBSIZE are 4380 bytes. If you call setsockopt() to reduce these two, for example, to a quarter like 1095 bytes, the memory usage to open a new TCP socket will drop from 16% to 4.7% as follows:
MQX -> Lightweight Memory Block Summary Size (Decimal) Owner Type
500 -> 500 0x10001 TCP Control Block;RTCS/TCP
4392 -> 1108 0x10001 TCP Tx Window;RTCS/TCP
4392 -> 1108 0x10001 TCP Rx Window;RTCS/TCP
148 -> 84 0x10001 TCP Send Clock;RTCS/TCP
If the problems persists please set a slower number, try next:
uint_32 value;
…
value = 256;
setsockopt(sock, SOL_TCP,OPT_TBSIZE,&value,sizeof(value));
setsockopt(sock, SOL_TCP,OPT_RBSIZE,&value,sizeof(value));
Try this to see if you can get more resources.
I am sorry but I did not catch your last question.
Regardsm
Garabo.