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_shutdown()

[FreeRTOS-Plus-TCP API Reference]

FreeRTOS_sockets.h

1BaseType_t FreeRTOS_shutdown( Socket_t xSocket, BaseType_t xHow );

Disable reads and writes on a connected TCP socket. A connected TCP socket must be gracefully shut down before it can be closed.

Parameters:

  • xSocket

    The socket being shut down.

  • xHow

    Must be set to FREERTOS_SHUT_RDWR.

    FreeRTOS-Plus-TCP does not currently use the xHow parameter as it always shuts down both reads and writes. xHow is included to ensure the function prototype conforms to the expected Berkeley sockets standard, and for compatibility with future FreeRTOS-Plus-TCP versions which may accept other parameter values.

Returns:

  • If the shutdown request was successful then 0 is returned. The shutdown being complete is indicated by FreeRTOS_recv() calls on the socket resulting in -pdFREERTOS_ERRNO_EINVAL being returned.

  • If xSocket is not a valid TCP socket then -pdFREERTOS_ERRNO_EOPNOTSUPP is returned.

  • If xSocket is a valid TCP socket but the socket is not connected to a remote socket then -pdFREERTOS_ERRNO_EOPNOTSUPP is returned.

Note that, because FreeRTOS does not implement errno, the behaviour in the presence of an error is necessarily different to that of connect() functions that are fully compliant with the expected Berkeley sockets behaviour.

Example usage:

The source code examples on both the Sending TCP Data and the Receiving TCP Data pages demonstrate a connected socket being shut down then closed.