heinbali01 wrote on Tuesday, June 11, 2019:
I am not sure if I should call FreeRTOS_shutdown() to each socket
FreeRTOS_shutdown()
is useful when you want to shut down connections in a graceful way. Graceful here means that your application takes the time to let the peer know that you want to end the connection. That is important because the peer can close their socket and release the resources. This closure normally takes less than 2 seconds, depending on the Internet speed. On a fast LAN, it will last a few hundred msec.
I wrote about FreeRTOS_shutdown()
here
and if so how do I determine all of the sockets.
Is there a list of open sockets.
FreeRTOS+TCP maintains two lists of sockets, one for TCP, and one for UDP. But these lists are kept for internal use.
I think that your tasks should know which sockets they are using.
Within a big OS, it is normal to start a daemon (telnetd, httpd, ftpd) that receives new clients. For each new client, it will spawn a new task (or thread) which will handle the client.
Within embedded, when you only have a limited amount of RAM, it is preferable to handle many (if not all) connections within a single task.
Here I summarise 3 methods of how to handle many socket within one task.
FreeRTOS_select()
is the most widely used method. The one with the semaphore is probably the easiest.
Or should I send a xSendEventToIpTask(eNetworkDownEvent)?
That won’t do much: this mechanisme is more a service to the user of the TCP/IP stack.
How do I know the sockets have shutdown ?
Like I mentioned, the owning task should know which socket(s) is owns. At the top-level, you should know what tasks are running that use sockets. The tasks own their sockets, so you may not bother with then from another task, that could lead to a crash.
Is there a users guide/manual for the FreeRTOS+TCP ?
Sure there is, on FreeRTOS.org/tcp
Please look at (examples of) using FreeRTOS_select()
And beside that, I would recommend reading about the BSD API calls.