Hi Neal,
thank you for your experiments on the new networking stack
Does any one know why the current tcp stack only handles 4 successive client connections before failing ?
Official Example
The mbed official TCP Server example does not have this problem, you can use it as a reference:
Socket API
In your example you are using a blocking call (default) to "send_all
", if anything goes wrong in the connection with your client, your server will remain stuck there without any chance to recover:
client.send_all(str, sizeof(str)-1);
Try to change that with something like a 3 seconds timeout:
client.send_all(str, sizeof(str)-1, 3000);
RTOS
Another thing you can do to increase the reliability of your program is to move the most stack intensive code to main
.
As you can see from the RTOS Memory Model documentation, the main
stack has room for growth in the whole free RAM memory. Any other thread has a fixed size stack that cannot grow at run time.
Remember that RAM in a microcontroller is a very scarce resource. Each RTOS thread has a relevant cost in terms of RAM for its stack. You want to avoid having a thread staying idle:
// Avoid code like this in a thread:
while(1) {
Thread::yield();
}
In your example, you can reduce the total number of threads by one (for example, move the ThreadProcSocket
to main
).
HTH,
Emilio
Does any one know why the current tcp stack only handles 4 successive client connections before failing ?
Running this program, and connecting to the mbed via "telnet 192.168.10.231 80" work 4 times, and on the fifth attempt, just hangs indefinitely
Import programtest_tcp_server
Test successive tcp connections
Last commit 31 Jul 2012 by Neal Horman
TIA for any help on this.