BaseType_t FreeRTOS_select( SocketSet_t xSocketSet, TickType_t xBlockTimeTicks );
Block on a "socket set" until an event of interest occurs on a socket
within the set. ipconfigSUPPORT_SELECT_FUNCTION must be set to 1 in
for FreeRTOS_select() (and its associated functions) to be available.
Socket Sets allow an application RTOS task to block on multiple sockets
To use a socket set:
Create a socket set by calling FreeRTOS_CreateSocketSet().
A socket set is equivalent to the Berkeley sockets fd_set type.
Add one or more sockets to the set using calls to FreeRTOS_FD_SET().
FreeRTOS_FD_SET() is equivalent to the Berkeley sockets FD_SET() macro.
Call FreeRTOS_Select() to test the
sockets in the set to see if any of the sockets have an event
If FreeRTOS_select() returns a non-zero value then check all
sockets in the set using a call to FreeRTOS_FD_ISSET()
to determine which events are pending.
A socket can only be a member of one set at any time.
The FreeRTOS_FD_CLR() API function removes a
socket from a set.
The socket set being tested.
The maximum time, in ticks, that the calling RTOS task will
remain in the Blocked state (with other tasks executing)
to wait for a member of the socket set to get an event.
If xBlockTimeTicks expired before a socket in the socket set had an event,
then zero is returned. Otherwise a non-zero value is returned. All sockets which
belong to the socket set must be checked by calling FreeRTOS_FD_ISSET()
If a socket in the set receives a signal,
causing the task that was blocked on the socket to abort its read operation,
then the call to FreeRTOS_select() will return -pdFREERTOS_ERRNO_EINTR.
static void prvMultipleSocketRxTask( void *pvParameters )
struct freertos_sockaddr xAddress;
uint32_t xClientLength = sizeof( struct freertos_sockaddr ), x;
uint32_t ulReceivedValue = 0;
const TickType_t xRxBlockTime = 0;
xFD_Set = FreeRTOS_CreateSocketSet();
for( x = 0; x < 2; x++ )
xSockets[x] = FreeRTOS_socket( FREERTOS_AF_INET,
xAddress.sin_port = FreeRTOS_htons( 1000 + x );
FreeRTOS_bind( xSockets[x], &xAddress, sizeof( struct freertos_sockaddr ) );
FreeRTOS_setsockopt( xSockets[x], 0, FREERTOS_SO_RCVTIMEO,
&xRxBlockTime, sizeof( xRxBlockTime ) );
FreeRTOS_FD_SET( xSockets[x], xFD_Set, eSELECT_READ );
for( ;; )
xResult = FreeRTOS_select( xFD_Set, portMAX_DELAY );
if( xResult != 0 )
for( x = 0; x < 2; x++ )
if( FreeRTOS_FD_ISSET ( xSockets[x], xFD_Set ) )
lBytes = FreeRTOS_recvfrom( xSockets[x], &( ulReceivedValue ),
sizeof( uint32_t ), 0, &xAddress,
Example use of the FreeRTOS_select() API function
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.