TCP Abstractions#
This module includes easy-to-use abstractions on top of the base TCP API.
Modules#
otTcpEndpointAndCircularSendBuffer
Enumerations#
Defines flags passed to otTcpCircularSendBufferWrite
.
Typedefs#
Represents a circular send buffer for use with a TCP endpoint.
Context structure to use with mbedtls_ssl_set_bio.
Functions#
Initializes a TCP circular send buffer.
Sends out data on a TCP endpoint, using the provided TCP circular send buffer to manage buffering.
Performs circular-send-buffer-specific handling in the otTcpForwardProgress callback.
Returns the amount of free space in the TCP circular send buffer.
Forcibly discards all data in the circular send buffer.
Deinitializes a TCP circular send buffer, detaching it if attached.
Non-blocking send callback to pass to mbedtls_ssl_set_bio.
Non-blocking receive callback to pass to mbedtls_ssl_set_bio.
Enumeration Documentation#
@25#
@25
Defines flags passed to otTcpCircularSendBufferWrite
.
Enumerator | |
---|---|
OT_TCP_CIRCULAR_SEND_BUFFER_WRITE_MORE_TO_COME |
114
of file include/openthread/tcp_ext.h
Typedef Documentation#
otTcpCircularSendBuffer#
typedef struct otTcpCircularSendBuffer otTcpCircularSendBuffer
Represents a circular send buffer for use with a TCP endpoint.
Using a circular send buffer is optional. Applications can use a TCP endpoint to send data by managing otLinkedBuffers directly. However, some applications may find it more convenient to have a circular send buffer; such applications can call otTcpCircularSendBufferWrite() to "attach" a circular send buffer to a TCP endpoint and send out data on that TCP endpoint, relying on the circular send buffer to manage the underlying otLinkedBuffers.
otTcpCircularSendBuffer is implemented on top of the otLinkedBuffer-based API provided by an otTcpEndpoint. Once attached to an otTcpEndpoint, an otTcpCircularSendBuffer performs all the work of managing otLinkedBuffers for the connection. This means that, once an otTcpCircularSendBuffer is attached to an otTcpEndpoint, the application should not call otTcpSendByReference() or otTcpSendByExtension() on that otTcpEndpoint. Instead, the application should use otTcpCircularSendBufferWrite() to add data to the send buffer.
The otTcpForwardProgress() callback is the intended way for users to learn when space becomes available in the circular send buffer. On an otTcpEndpoint to which an otTcpCircularSendBuffer is attached, the application MUST install an otTcpForwardProgress() callback and call otTcpCircularSendBufferHandleForwardProgress() on the attached otTcpCircularSendBuffer at the start of the callback function. It is recommended that the user NOT install an otTcpSendDone() callback, as all management of otLinkedBuffers is handled by the circular send buffer.
The application should not inspect the fields of this structure directly; it should only interact with it via the TCP Circular Send Buffer API functions whose signature are provided in this file.
98
of file include/openthread/tcp_ext.h
otTcpEndpointAndCircularSendBuffer#
typedef struct otTcpEndpointAndCircularSendBuffer otTcpEndpointAndCircularSendBuffer
Context structure to use with mbedtls_ssl_set_bio.
225
of file include/openthread/tcp_ext.h
Function Documentation#
otTcpCircularSendBufferInitialize#
void otTcpCircularSendBufferInitialize (otTcpCircularSendBuffer * aSendBuffer, void * aDataBuffer, size_t aCapacity)
Initializes a TCP circular send buffer.
[in] | aSendBuffer | A pointer to the TCP circular send buffer to initialize. |
[in] | aDataBuffer | A pointer to memory to use to store data in the TCP circular send buffer. |
[in] | aCapacity | The capacity, in bytes, of the TCP circular send buffer, which must equal the size of the memory pointed to by |
108
of file include/openthread/tcp_ext.h
otTcpCircularSendBufferWrite#
otError otTcpCircularSendBufferWrite (otTcpEndpoint * aEndpoint, otTcpCircularSendBuffer * aSendBuffer, const void * aData, size_t aLength, size_t * aWritten, uint32_t aFlags)
Sends out data on a TCP endpoint, using the provided TCP circular send buffer to manage buffering.
[in] | aEndpoint | The TCP endpoint on which to send out data. |
[in] | aSendBuffer | The TCP circular send buffer into which to copy data. |
[in] | aData | A pointer to data to copy into the TCP circular send buffer. |
[in] | aLength | The length of the data pointed to by |
[out] | aWritten | Populated with the amount of data copied into the send buffer, which might be less than |
[in] | aFlags | Flags specifying options for this operation (see enumeration above). |
Once this function is called, aSendBuffer
and aEndpoint
are considered "attached" to each other. While they are attached, ALL send operations for aEndpoint
must be made using aSendBuffer
and ALL operations on aSendBuffer
must be associated with aEndpoint
.
The only way to "detach" a TCP circular send buffer and a TCP endpoint is to wait for the send buffer to become completely empty. This can happen in two ways: (1) all data in the send buffer is sent and acknowledged in the normal course of TCP protocol operation, or (2) the connection is terminated.
The recommended usage pattern is to use a single TCP circular send buffer with a TCP endpoint, and to send data on that TCP endpoint only via its associated TCP circular buffer. This recommended usage pattern sidesteps the issues described above by always using a TCP endpoint and TCP circular send buffer together.
If the circular send buffer reaches capacity, only a prefix of the provided data is copied into the circular send buffer.
153
of file include/openthread/tcp_ext.h
otTcpCircularSendBufferHandleForwardProgress#
void otTcpCircularSendBufferHandleForwardProgress (otTcpCircularSendBuffer * aSendBuffer, size_t aInSendBuffer)
Performs circular-send-buffer-specific handling in the otTcpForwardProgress callback.
[in] | aSendBuffer | A pointer to the TCP circular send buffer for the endpoint for which otTcpForwardProgress() was invoked. |
[in] | aInSendBuffer | Value of |
The application is expected to install an otTcpForwardProgress() callback on the otTcpEndpoint, and call this function at the start of the callback function for circular-send-buffer-specific processing.
In the callback function, the application can determine the amount of free space in the circular send buffer by calling otTcpCircularSendBufferFreeSpace(), or by comparing aInSendBuffer
with the send buffer's capacity, chosen by the user when calling otTcpCircularSendBufferInitialize().
178
of file include/openthread/tcp_ext.h
otTcpCircularSendBufferGetFreeSpace#
size_t otTcpCircularSendBufferGetFreeSpace (const otTcpCircularSendBuffer * aSendBuffer)
Returns the amount of free space in the TCP circular send buffer.
[in] | aSendBuffer | A pointer to the TCP circular send buffer whose amount of free space to return. |
This operation will always succeed.
Returns
The amount of free space in the send buffer.
189
of file include/openthread/tcp_ext.h
otTcpCircularSendBufferForceDiscardAll#
void otTcpCircularSendBufferForceDiscardAll (otTcpCircularSendBuffer * aSendBuffer)
Forcibly discards all data in the circular send buffer.
[in] | aSendBuffer | The TCP circular send buffer whose data to discard. |
The application is expected to call this function when a TCP connection is terminated unceremoniously (e.g., if the application calls otTcpEndpointAbort() or is informed of a reset connection via the otTcpConnectionLost() callback).
Calling this function on a nonempty TCP circular send buffer attached to a TCP endpoint results in undefined behavior.
204
of file include/openthread/tcp_ext.h
otTcpCircularSendBufferDeinitialize#
otError otTcpCircularSendBufferDeinitialize (otTcpCircularSendBuffer * aSendBuffer)
Deinitializes a TCP circular send buffer, detaching it if attached.
[in] | aSendBuffer | The TCP circular send buffer to deinitialize. |
If the TCP circular send buffer is not empty, then this operation will fail.
216
of file include/openthread/tcp_ext.h
otTcpMbedTlsSslSendCallback#
int otTcpMbedTlsSslSendCallback (void * aCtx, const unsigned char * aBuf, size_t aLen)
Non-blocking send callback to pass to mbedtls_ssl_set_bio.
[in] | aCtx | A pointer to an otTcpEndpointAndCircularSendBuffer. |
[in] | aBuf | The data to add to the send buffer. |
[in] | aLen | The amount of data to add to the send buffer. |
Returns
The number of bytes sent, or an mbedtls error code.
236
of file include/openthread/tcp_ext.h
otTcpMbedTlsSslRecvCallback#
int otTcpMbedTlsSslRecvCallback (void * aCtx, unsigned char * aBuf, size_t aLen)
Non-blocking receive callback to pass to mbedtls_ssl_set_bio.
[in] | aCtx | A pointer to an otTcpEndpointAndCircularSendBuffer. |
[out] | aBuf | The buffer into which to receive data. |
[in] | aLen | The maximum amount of data that can be received. |
Returns
The number of bytes received, or an mbedtls error code.
247
of file include/openthread/tcp_ext.h