# TCP - Platform

This module includes the platform abstraction for TCP connections and listeners.

## Summary

All APIs in this module are applicable only when `OPENTHREAD_CONFIG_PLATFORM_TCP_ENABLE` feature is enabled.

| ### Enumerations ||
|---|---|
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga88c39e90edc4d2ae62a662f83ab98a73{ https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gga88c39e90edc4d2ae62a662f83ab98a73a6d143616aa82150aa8585ccf5fe23cc5, https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gga88c39e90edc4d2ae62a662f83ab98a73a88918ac8fc4f26ea8626b0c9eb8ce58f, https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gga88c39e90edc4d2ae62a662f83ab98a73a7f4efe339033d2bd30e67095f9ca0059, https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gga88c39e90edc4d2ae62a662f83ab98a73a2bf42db2d9e6f2d7c8cf93f652229db9, https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gga88c39e90edc4d2ae62a662f83ab98a73af9f225be718215da307a70d28188d56e }` | enumDefines the reason for a TCP connection disconnection. |

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gaf9b8a680544e3b9df7edb19739ac063f` | typedef `struct https://openthread.io/reference/struct/ot-plat-tcp-connection` Represents a TCP connection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga59c8341822dbab224b35675fcc419bed` | typedef `enum https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga88c39e90edc4d2ae62a662f83ab98a73` Defines the reason for a TCP connection disconnection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga40bb5db489eae73e906f3b7dfdb84d9f` | typedef `struct https://openthread.io/reference/struct/ot-plat-tcp-listener` Represents a TCP listener. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga9a6b7aadfd2bfccfee072372de993cdf` | typedef `struct https://openthread.io/reference/struct/ot-plat-tcp-sock-addr` Represents a TCP socket address. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga8a29c83849c4ca6620e814df4f86b800(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `void` Aborts the TCP connection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga8846079a3bf3e513d075ddf37cc12230(https://openthread.io/reference/struct/ot-plat-tcp-listener *aListener, const https://openthread.io/reference/struct/ot-plat-tcp-sock-addr *aPeerSockAddr)` | `https://openthread.io/reference/struct/ot-plat-tcp-connection *` Callback to accept an incoming TCP connection request on an active listener. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga563e29475f55ce53943ddfd93bb23558(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `void` Gracefully closes the TCP connection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga3823ac8909e20feb30cd6ae110ecd597(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn, const https://openthread.io/reference/struct/ot-plat-tcp-sock-addr *aPeerSockAddr, const https://openthread.io/reference/struct/ot-plat-tcp-sock-addr *aLocalSockAddr)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Initiates a TCP connection to a peer. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gac95d5f1159571118b59ee89c4c5d01ae(https://openthread.io/reference/struct/ot-plat-tcp-listener *aListener)` | `void` Disables a TCP listener. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gafd16312c4610ab9030c246a18213697c(https://openthread.io/reference/struct/ot-plat-tcp-listener *aListener, const https://openthread.io/reference/struct/ot-plat-tcp-sock-addr *aLocalSockAddr)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Enables a TCP listener. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga41eada36ec220f373006abbeb9629336(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *` Gets the OpenThread instance associated with a given TCP connection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga17249767797c074340fa847bf7cf2f08(https://openthread.io/reference/struct/ot-plat-tcp-listener *aListener)` | `https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *` Gets the OpenThread instance associated with a given TCP listener. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga7a9a5d35e54f3a1d231c7cfecbf00f4c(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `void` Callback to notify the connection establishment. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga0c34e3f9a7b81dc825b09215ce366259(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn, https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga88c39e90edc4d2ae62a662f83ab98a73 aReason)` | `void` Callback to notify the connection disconnection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1a229d58993f5b7fcec2b842fc91631a(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn, const uint8_t *aBuffer, uint16_t aLength)` | `void` Callback to notify the reception of data on a connection. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1aa44b32b54a796821c732251b006257(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `void` Callback to notify that the platform is ready to accept more transmit data. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga840af52dfa4172b0857eb333abd4c01c(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `bool` Indicates whether the TCP connection is currently in the connecting state. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga762adeb0d3fe14a6c5cbd3b418e0a42c(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `bool` Indicates whether the TCP connection has pending data for transmission. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gac9580cd332bd95b777e768e0ffcfeb58(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-plat-tcp-connection *aPrevConn)` | `https://openthread.io/reference/struct/ot-plat-tcp-connection *` Iterates through the active TCP connections. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga96b964bcf29928c7df56f6a3797a946a(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-plat-tcp-listener *aPrevListener)` | `https://openthread.io/reference/struct/ot-plat-tcp-listener *` Iterates through the active TCP listeners. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1522135dce44d6e06be9a8644ed463a0(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn)` | `void` Notifies the platform that there is pending data for transmission. |
| `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gaf8f153e7614f9d251eaf37cfef8ef8e0(https://openthread.io/reference/struct/ot-plat-tcp-connection *aConn, const uint8_t *aBuffer, uint16_t aLength)` | `uint16_t` Sends data over an active TCP connection. |

| ### Structs ||
|---|---|
| [otPlatTcpConnection](https://openthread.io/reference/struct/ot-plat-tcp-connection) | Represents a TCP connection. |
| [otPlatTcpListener](https://openthread.io/reference/struct/ot-plat-tcp-listener) | Represents a TCP listener. |
| [otPlatTcpSockAddr](https://openthread.io/reference/struct/ot-plat-tcp-sock-addr) | Represents a TCP socket address. |

| ### Unions ||
|---|---|
| [otPlatTcpPlatformData](https://openthread.io/reference/union/ot-plat-tcp-platform-data) | Represents platform-specific data associated with a connection or a listener. |

## Enumerations

### otPlatTcpDisconnectReason

```
 otPlatTcpDisconnectReason
```
Defines the reason for a TCP connection disconnection.

| Properties ||
|---|---|
| `OT_PLAT_TCP_DISCONNECT_REASON_CLOSED` | Connection was gracefully closed. |
| `OT_PLAT_TCP_DISCONNECT_REASON_ERROR` | Connection was aborted due to other errors. |
| `OT_PLAT_TCP_DISCONNECT_REASON_REFUSED` | Connection was refused by the peer (RST received during handshake). |
| `OT_PLAT_TCP_DISCONNECT_REASON_RESET` | Connection was reset by the peer (RST received on established conn). |
| `OT_PLAT_TCP_DISCONNECT_REASON_TIMEOUT` | Connection timed out (e.g., failed to connect or keepalive failure). |

## Typedefs

### otPlatTcpConnection

```
struct otPlatTcpConnection otPlatTcpConnection
```
Represents a TCP connection.

The OpenThread core owns and manages the `https://openthread.io/reference/struct/ot-plat-tcp-connection` instances. The platform should track the pointers to these instances and pass them when invoking the `otPlatTcpHandle*` callbacks. The `https://openthread.io/reference/struct/ot-plat-tcp-connection *` can be viewed as a "descriptor" or "handle" to the connection.

The `https://openthread.io/reference/struct/ot-plat-tcp-connection` instance remains valid as long as the connection is active.

### otPlatTcpDisconnectReason

```
enum otPlatTcpDisconnectReason otPlatTcpDisconnectReason
```
Defines the reason for a TCP connection disconnection.

### otPlatTcpListener

```
struct otPlatTcpListener otPlatTcpListener
```
Represents a TCP listener.

The OpenThread core owns and manages the `https://openthread.io/reference/struct/ot-plat-tcp-listener` instances. The platform should track the pointers to these instances and use them when invoking the callbacks. The `https://openthread.io/reference/struct/ot-plat-tcp-listener *` can be viewed as a "descriptor" or "handle" to the listener.

### otPlatTcpSockAddr

```
struct otPlatTcpSockAddr otPlatTcpSockAddr
```
Represents a TCP socket address.

## Functions

### otPlatTcpAbort

```
void otPlatTcpAbort(
  otPlatTcpConnection *aConn
)
```
Aborts the TCP connection.

This function forcefully terminates the connection. Any unsent data is discarded.

After this call, the platform must forget the `aConn`. Importantly, it must not invoke any callbacks using the `aConn` any longer, including `otPlatTcpHandleDisconnected`. This effectively indicates to the platform that the OpenThread core is de-allocating the `aConn` instance and it is no longer valid.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |

### otPlatTcpAccept

```
otPlatTcpConnection * otPlatTcpAccept(
  otPlatTcpListener *aListener,
  const otPlatTcpSockAddr *aPeerSockAddr
)
```
Callback to accept an incoming TCP connection request on an active listener.

This function is implemented and provided by the OpenThread stack for the platform to use.

The callback returns a pointer to an `https://openthread.io/reference/struct/ot-plat-tcp-connection` for the new connection. If the callback returns NULL, the incoming connection is rejected.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aListener` | The TCP listener. | | `[in] aPeerSockAddr` | The peer's socket address. | |
| **Returns** | A pointer for the newly accepted connection, or NULL to reject the connection request. |

### otPlatTcpClose

```
void otPlatTcpClose(
  otPlatTcpConnection *aConn
)
```
Gracefully closes the TCP connection.

This function initiates a graceful closure of the connection. The platform should transmit any remaining data before performing the standard TCP connection termination.

Once the connection is fully disconnected, or if it is already closed, or if an error occurs during the close operation, the platform must indicate this by invoking the `otPlatTcpHandleDisconnected` callback.

The platform must always call `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga0c34e3f9a7b81dc825b09215ce366259` to report the final outcome of the connection. It is permissible for the platform implementation to invoke this callback directly from within `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga563e29475f55ce53943ddfd93bb23558` before returning. The OpenThread stack will handle this correctly.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |

### otPlatTcpConnect

```
otError otPlatTcpConnect(
  otPlatTcpConnection *aConn,
  const otPlatTcpSockAddr *aPeerSockAddr,
  const otPlatTcpSockAddr *aLocalSockAddr
)
```
Initiates a TCP connection to a peer.

The platform should initiate a TCP connection to the `aPeerSockAddr`.

The `aLocalSockAddr` specifies the local address and port to bind to before connecting. It can be NULL if the OpenThread stack does not specify a preference. If provided, fields within `aLocalSockAddr` may still be left unspecified (e.g., the IP address can be all zeros, or the port can be zero). In all such cases, the platform and the underlying TCP stack should automatically select an appropriate local IP address and/or an ephemeral port.

If `OT_ERROR_NONE` is returned (indicating successful initialization of the connection process), the platform must subsequently report the status. Upon successful connection establishment, the platform must invoke the `otPlatTcpHandleConnected` callback. If it fails to establish the connection, the `otPlatTcpHandleDisconnected` callback must be called to indicate the failure.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | | `[in] aPeerSockAddr` | The peer's socket address. | | `[in] aLocalSockAddr` | The local socket address. Can be NULL. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully initiated the connection. | | `OT_ERROR_FAILED` | Failed to initiate the connection. | |

### otPlatTcpDisableListener

```
void otPlatTcpDisableListener(
  otPlatTcpListener *aListener
)
```
Disables a TCP listener.

The platform should stop listening for incoming connections on the socket associated with the listener. Any incoming connection requests that have not yet been accepted should be discarded.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aListener` | The TCP listener. | |

### otPlatTcpEnableListener

```
otError otPlatTcpEnableListener(
  otPlatTcpListener *aListener,
  const otPlatTcpSockAddr *aLocalSockAddr
)
```
Enables a TCP listener.

The platform should start listening for incoming TCP connections on the provided `aLocalSockAddr`. When an incoming connection request is received, the platform must invoke the `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga8846079a3bf3e513d075ddf37cc12230` callback to accept the request.

The `aLocalSockAddr` specifies the local interface, address, and port to bind to. Importantly, the port number within `aLocalSockAddr` must not be zero. The IP address may be unspecified (all zeros) to indicate that the listener should accept connections on any local address.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aListener` | The TCP listener. | | `[in] aLocalSockAddr` | The local socket address to listen on. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully enabled or disabled the listener. | | `OT_ERROR_ALREADY` | Already listening on the same port/address. | | `OT_ERROR_FAILED` | Failed to enable the listener. | |

### otPlatTcpGetInstanceForConnection

```
otInstance * otPlatTcpGetInstanceForConnection(
  otPlatTcpConnection *aConn
)
```
Gets the OpenThread instance associated with a given TCP connection.

This function is provided by OpenThread core. Platform implementations can use it to get the OpenThread instance associated with an active `https://openthread.io/reference/struct/ot-plat-tcp-connection`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |
| **Returns** | The OpenThread instance. |

### otPlatTcpGetInstanceForListener

```
otInstance * otPlatTcpGetInstanceForListener(
  otPlatTcpListener *aListener
)
```
Gets the OpenThread instance associated with a given TCP listener.

This function is provided by OpenThread core. Platform implementations can use it to get the OpenThread instance associated with an active `https://openthread.io/reference/struct/ot-plat-tcp-listener`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aListener` | The TCP listener. | |
| **Returns** | The OpenThread instance. |

### otPlatTcpHandleConnected

```
void otPlatTcpHandleConnected(
  otPlatTcpConnection *aConn
)
```
Callback to notify the connection establishment.

This callback is implemented and provided by the OpenThread stack. It must be invoked by the platform to indicate that the TCP handshake is complete and that the connection is now established.

The platform must call this after a successful call to `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga3823ac8909e20feb30cd6ae110ecd597` when the connection is established. For incoming connection requests (on an `https://openthread.io/reference/struct/ot-plat-tcp-listener`), the platform must call this after the `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga8846079a3bf3e513d075ddf37cc12230` callback returns successfully and when the connection is established.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |

### otPlatTcpHandleDisconnected

```
void otPlatTcpHandleDisconnected(
  otPlatTcpConnection *aConn,
  otPlatTcpDisconnectReason aReason
)
```
Callback to notify the connection disconnection.

This function is implemented and provided by the OpenThread stack for the platform to use.

This callback should be invoked by the platform when it fails to establish a connection, when an established connection is successfully closed (by both endpoints), when it times out, or is reset or aborted.

After this callback is invoked, the `https://openthread.io/reference/struct/ot-plat-tcp-connection` instance is no longer valid. The platform must not use it in any future callbacks.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | | `[in] aReason` | The reason for the disconnection. | |

### otPlatTcpHandleReceive

```
void otPlatTcpHandleReceive(
  otPlatTcpConnection *aConn,
  const uint8_t *aBuffer,
  uint16_t aLength
)
```
Callback to notify the reception of data on a connection.

This function is implemented and provided by the OpenThread stack for the platform to use.

The platform invokes this callback to provide received data to the OpenThread stack. The provided `aBuffer` only needs to remain valid for the duration of this call. The OpenThread stack will process and copy the bytes as needed, and will not retain the `aBuffer` pointer after the function returns.

Since TCP is a stream protocol, data can arrive in arbitrarily sized chunks. The platform does not need to buffer or reassemble these; it can invoke this callback immediately as data is received, even if it is expecting more data. The OpenThread stack handles all stream-level behavior, processing, and retention of the received data. This helps simplify the platform implementation.

On certain platforms (such as standard POSIX), a return value of 0 from `read()` or `recv()` indicates an End-of-File (EOF) or graceful closure by the peer. The platform implementation must check for this condition and report it by invoking `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga0c34e3f9a7b81dc825b09215ce366259` with the reason set to `OT_PLAT_TCP_DISCONNECT_REASON_CLOSED`. Importantly, calling `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1a229d58993f5b7fcec2b842fc91631a` with `aLength` set to zero does not signify a graceful closure in the `otPlatTcp` APIs; such a call is treated as a no-op receive event by the OpenThread stack and is ignored.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | | `[in] aBuffer` | A pointer to the buffer containing the received data. Must not be NULL if `aLength` \> 0. | | `[in] aLength` | The length (in bytes) of the received data. | |

### otPlatTcpHandleTxReady

```
void otPlatTcpHandleTxReady(
  otPlatTcpConnection *aConn
)
```
Callback to notify that the platform is ready to accept more transmit data.

This function is implemented and provided by the OpenThread stack for the platform to use.

The platform should invoke this callback when it is ready to accept more data for transmission over the TCP connection, in response to a prior `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1522135dce44d6e06be9a8644ed463a0` call. Upon being called, the OpenThread stack will use `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gaf8f153e7614f9d251eaf37cfef8ef8e0` to provide the pending TX data to the platform. The stack may call `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1gaf8f153e7614f9d251eaf37cfef8ef8e0` multiple times during the execution of this callback.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |

### otPlatTcpIsConnecting

```
bool otPlatTcpIsConnecting(
  otPlatTcpConnection *aConn
)
```
Indicates whether the TCP connection is currently in the connecting state.

This function is provided by the OpenThread stack. The platform can use it to determine if a TCP connection is still waiting for the TCP handshake to complete.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |
| Return Values | |---|---| | `TRUE` | The connection is currently in the connecting state. | | `FALSE` | The connection is not in the connecting state. | |

### otPlatTcpIsTxPending

```
bool otPlatTcpIsTxPending(
  otPlatTcpConnection *aConn
)
```
Indicates whether the TCP connection has pending data for transmission.

This function is provided by the OpenThread stack. The platform can use it to check if there is any pending data for transmission over the TCP connection.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |
| Return Values | |---|---| | `TRUE` | The connection has pending transmit data. | | `FALSE` | The connection does not have pending transmit data. | |

### otPlatTcpIterateConnections

```
otPlatTcpConnection * otPlatTcpIterateConnections(
  otInstance *aInstance,
  otPlatTcpConnection *aPrevConn
)
```
Iterates through the active TCP connections.

This function can be used to iterate over all currently active TCP connections associated with the OpenThread instance. It allows platform implementations to process or manage connections without needing to maintain their own list of active connections.

The iteration is guaranteed to remain consistent and safe even if callbacks are invoked during the process. For example, if a connection is reported as disconnected via `otPlatTcpHandleDisconnected` during iteration, the OpenThread stack ensures that the connection entry remains valid until the iteration is completed.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | The OpenThread instance. | | `[in] aPrevConn` | A pointer to the previous connection, or `NULL` to start the iteration from the beginning. | |
| **Returns** | A pointer to the next connection, or `NULL` if there are no more connections. |

### otPlatTcpIterateListeners

```
otPlatTcpListener * otPlatTcpIterateListeners(
  otInstance *aInstance,
  otPlatTcpListener *aPrevListener
)
```
Iterates through the active TCP listeners.

This function can be used to iterate over all currently active TCP listeners associated with the OpenThread instance. It allows platform implementations to process or manage listeners without needing to maintain their own list of active listeners.

The iteration is guaranteed to remain consistent even if callbacks (e.g., `otPlatTcpAccept`) are invoked during the process.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | The OpenThread instance. | | `[in] aPrevListener` | A pointer to the previous listener, or `NULL` to start the iteration from the beginning. | |
| **Returns** | A pointer to the next listener, or `NULL` if there are no more listeners. |

### otPlatTcpNotifyTxPending

```
void otPlatTcpNotifyTxPending(
  otPlatTcpConnection *aConn
)
```
Notifies the platform that there is pending data for transmission.

This function is called by the OpenThread stack when it has new data for transmission. After this call, the platform should indicate when it is ready to accept the data by invoking the `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1aa44b32b54a796821c732251b006257` callback.

The platform can also use `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga762adeb0d3fe14a6c5cbd3b418e0a42c` to check if there is pending data for transmission.

It is permissible for the platform implementation to invoke the `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1aa44b32b54a796821c732251b006257` callback directly from within `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1522135dce44d6e06be9a8644ed463a0` before returning, if the underlying TCP transmit buffer is already available. The OpenThread stack will handle this correctly.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | |

### otPlatTcpSend

```
uint16_t otPlatTcpSend(
  otPlatTcpConnection *aConn,
  const uint8_t *aBuffer,
  uint16_t aLength
)
```
Sends data over an active TCP connection.

This function is called by the OpenThread stack to provide data for the platform to transmit. The data is provided in a buffer. The platform should copy as much data as it can from the given buffer into its underlying platform transmit buffer.

The provided `aBuffer` is temporary. The platform must not store the pointer or assume the content remains valid after this function returns. All required data must be copied during this call.

The OpenThread stack typically invokes this function from the `https://openthread.io/reference/group/plat-tcp#group__plat-tcp_1ga1aa44b32b54a796821c732251b006257` callback. However, the platform implementation must not assume this and should support being called at any time. If there is no space available to accept any data, the platform can return zero.

The OpenThread stack may call this function multiple times back-to-back to provide all queued transmit content in chunks. The platform should be prepared to handle consecutive calls efficiently.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aConn` | The TCP connection. | | `[in] aBuffer` | A pointer to the buffer containing the data to send. | | `[in] aLength` | The length (in bytes) of the data in the buffer. | |
| **Returns** | The actual number of bytes accepted for transmission. |

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).