Okay, thank you for your reply.
I noticed you used two different timeout. One, when starting the connection and the second, after the connection has been established. In my own code, I configured only one timeout at the start of the connection (following the convention I saw in the demo application and many sources online).
Can we still make FreeRTOS_connect and FreeRTOS_accept return once the connection or socket closes without having them wait for a timeout (since the socket is already closed and we can know when the socket closes)? That way, even if users configure longer timeouts, those system calls would still return if the socket or connection gets closed.