Download FreeRTOS
 

Quality RTOS & Embedded Software

LIBRARIES
WHAT'S NEW
Simplifying Authenticated Cloud Connectivity for Any Device.
Designing an energy efficient and cloud-connected IoT solution with CoAP.
Introducing FreeRTOS Kernel version 11.0.0:
FreeRTOS Roadmap and Code Contribution process.
OPC-UA over TSN with FreeRTOS.

FreeRTOS_FD_SET()

[FreeRTOS-Plus-TCP API Reference]

FreeRTOS_sockets.h
void FreeRTOS_FD_SET( Socket_t xSocket, SocketSet_t xSocketSet, BaseType_t xSelectBits );
		

Add a socket to a socket set, and set the event bits of interest for the added socket. A socket can only be a member of one set at any time.

ipconfigSUPPORT_SELECT_FUNCTION must be set to 1 in FreeRTOSIPConfig.h for FreeRTOS_FD_SET() to be available.


Socket Sets allow an application RTOS task to block on multiple sockets simultaneously.

To use a socket set:

  1. Create a socket set by calling FreeRTOS_CreateSocketSet(). A socket set is equivalent to the Berkeley sockets fd_set type.

  2. 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.

  3. Call FreeRTOS_Select() to test the sockets in the set to see if any of the sockets have an event pending.

  4. 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.

The event bits of interest are set using the xSelectBits parameter, which can take a bitwise OR combination of one or more of the following values:

eSELECT_READ For a socket that is reading data, the eSELECT_READ event will be pending in a socket as long as the socket contains unread data.

For a socket that is listening for new connections, the eSELECT_READ event will be pended each time a new connection is received.

eSELECT_WRITE The eSELECT_WRITE event will remain pending as long as the socket has space for writing.

If a TCP socket is actively connecting to a pear the eSELECT_WRITE event will be triggered as soon as the connection is established.

One the eSELECT_WRITE event has been pended it should either be disabled, or the caller should write enough data to the socket so as to completely fill up the transmit buffer - otherwise the pending eSELECT_WRITE event will not be cleared.

eSELECT_EXCEPT The eSELECT_EXCEPT event will become pending if the socket gets disconnected.

eSELECT_INTR If any socket is signaled during the call, using FreeRTOS_SignalSocket() or FreeRTOS_SignalSocketFromISR(), then eSELECT_INTR is returned. Note that it's triggered only when ipconfigSUPPORT_SIGNALS is defined.

The FreeRTOS_FD_CLR() API function is used to clear event bits or remove a socket from a socket set.

Parameters:

xSocket   The socket being added to the set.

xSocketSet   The socket set to which the socket is being added.

xSelectBits   The events that will cause the socket to unblock a call to FreeRTOS_select(). See the table above for valid values.

Returns:

void.

Example usage:

See the example on the FreeRTOS_select() documentation page.

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.