Shutting Down and Closing a TCP Socket
A TCP socket that is not connected can be closed using the
Part of the FreeRTOS+TCP Networking Tutorial
A TCP socket that is connected should not be closed until the connection has been shut down. To gracefully shut down a socket first call FreeRTOS_shutdown(), then wait for read attempts on the socket to return FREERTOS_EINVAL, indicating that the socket is no longer connected.