A standard practice for managing multiple socket connections is use poll
or select
. This allows the calling thread (or task, in this case) to block until the operating system detects that data is available to read (at which point it resumes the task)
In FreeRTOS, the system API provides a mechanism for this called FreeRTOS_select. However, the documentation specifies:
FreeRTOS_select
takes a socket-set of type xSocketSet_t
(see link above) which contains sockets of type xSocket
. xSocket
is created with FreeRTOS_socket.FreeRTOS_socket
states that xType
(socket type) quote: "Must be set to FREERTOS_SOCK_DGRAM" (see link above).If you can only create datagram sockets, you can't use this select call with stream sockets. When searching for creating stream sockets, I found that an identical call to FreeRTOS_socket
here in the example. However, this is for something called "FreeRTOS + TCP" and the API doesn't have an example for select
. The type of the socket returned is not xSocket_t
but Socket_t
.
So how can you use select with TCP sockets? There doesn't seem to be a straightforward answer anywhere about this. The problem I have is that I would like to use the built in select
functions of FreeRTOS because they can automatically manage the task for me. Using a library-based select may not be possible.
Looks like I was wrong, there is a dedicated FreeRTOS_select
call for select with TCP too available at this link. It's just difficult to locate. This is my fault for not spending enough time trying to find the API calls using other means.