Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Updated Jul 2025

FreeRTOS_FD_CLR()

[FreeRTOS-Plus-TCP API Reference]

FreeRTOS_sockets.h

1void FreeRTOS_FD_CLR( Socket_t xSocket, SocketSet_t xSocketSet, BaseType_t xBitsToClear );

Sockets in a socket set have a number of associated event bits of interest. An event bit of interest becoming set will cause the socket to unblock a call to FreeRTOS_select(). Event bits of interest are set using the FreeRTOS_FD_SET() API function, and cleared using the FreeRTOS_FD_CLR() API function. If all the event bits are clear then the socket will be removed from the socket set.

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

Each socket member has its own set of event bits, which can be a bitwise OR combination 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.

Parameters:

  • xSocket

    The socket having a bit of interest cleared or being removed from the socket set.

  • xSocketSet

    The socket set the socket is a member of.

  • xBitsToClear

    The bits which should be cleared, use 'eSELECT_ALL' to clear all bits and remove the socket from the set.

Returns:

void

1/* FreeRTOS includes. */
2#include "FreeRTOS.h"
3#include "task.h"
4#include "queue.h"
5
6/* FreeRTOS-Plus-TCP includes. */
7#include "FreeRTOS_IP.h"
8#include "FreeRTOS_Sockets.h"
9
10void vConnectExample( )
11{
12Socket_t xSocket;
13struct freertos_sockaddr xEchoServerAddress;
14const TickType_t xZeroTimeOut = 0;
15SocketSet_t xSocketSet;
16
17 /* Create a TCP socket. */
18 xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
19
20 /* Create a socket set. */
21 xSocketSet = FreeRTOS_CreateSocketSet()( );
22
23 /* Make the socket a member of the set.
24 Only the WRITE event can unblock a call to select() */
25 FreeRTOS_FD_SET( xSocket, xSocketSet, eSELECT_WRITE );
26
27 /* When working with select(), time-outs on API's aren't necessary */
28 FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xZeroTimeOut, sizeof( xZeroTimeOut ) );
29 FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xZeroTimeOut, sizeof( xZeroTimeOut ) );
30
31 /* Fill in the peer's address */
32 xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
33 xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
34 configECHO_SERVER_ADDR1,
35 configECHO_SERVER_ADDR2,
36 configECHO_SERVER_ADDR3 );
37
38 /* Now initiate an active connect procedure to a peer. This call is non-blocking */
39 FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) );
40
41 /* Now block for at most 30 seconds. A successful connection will unblock
42 select() with a eSELECT\_WRITE event */
43 if( FreeRTOS_select( xSocketSet, 30000 ) != 0 )
44 {
45 BaseType_t xMask = FreeRTOS_FD_ISSET ( xSocket, xSocketSet );
46 if( xMask != 0 )
47 {
48 /* Clear the WRITE event bit, it is not interesting any more */
49 FreeRTOS_FD_CLR( xSocket, xSocketSet, eSELECT_WRITE );
50
51 /* Set the READ event bit */
52 FreeRTOS_FD_SET( xSocket, xSocketSet, eSELECT_READ );
53 }
54 }
55}

Example use of the FreeRTOS_FD_SET / FD_CLR / FD_ISSET() API functions