Shutting down the IP stack

larrydew wrote on Saturday, June 08, 2019:

I have an app the user can change the IP configuation (Address, Mask…) My question is there a shutdown function that kills all of the tasks related to IP functions? I think I need to kill all of them (HTTP, FTP, UDP and the base IP) and then re-start them with new parameters. How do I know when the tasks have stopped so that I can restart them? Is there an order as to kill the tasks? I prefer not doing an entire system reset from a watchdog timeout or force a system reset.

heinbali01 wrote on Sunday, June 09, 2019:

Recently there was a comparable question in this forum.
As it works now, FreeRTOS_IPInit() can and shall only be called once.

In stead of killing tasks, I would always choose to send a message to the task, so that it can stop running, release all resources, and kill itself.

I have always been lazy: as soon as the network settings chang drastically, the device will reboot itself.

larrydew wrote on Monday, June 10, 2019:

I am really confused. I have read the links you provided and I am not sure if I should call FreeRTOS_shutdown() to each socket and if so how do I determine all of the sockets. Is there a list of open sockets. Or should I send a xSendEventToIpTask(eNetworkDownEvent) ? How do I know the sockets have shutdown ?
Is there a users guide/manual for the FreeRTOS+TCP ?

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.

larrydew wrote on Tuesday, June 11, 2019:

Thanks, I have some reading to do.