TCP Abstractions
This module includes easy-to-use abstractions on top of the base TCP API.
Classes |
|
struct | otTcpCircularSendBuffer |
This structure represents a circular send buffer for use with a TCP endpoint.
|
Typedefs |
|
typedef struct otTcpCircularSendBuffer | otTcpCircularSendBuffer |
This structure represents a circular send buffer for use with a TCP endpoint.
|
Enumerations |
|
enum | { OT_TCP_CIRCULAR_SEND_BUFFER_WRITE_MORE_TO_COME = 1 << 0 } |
This enumeration defines flags passed to
otTcpCircularSendBufferWrite
.
|
Functions |
|
void | otTcpCircularSendBufferInitialize ( otTcpCircularSendBuffer *aSendBuffer, void *aDataBuffer, size_t aCapacity) |
Initializes a TCP circular send buffer.
|
|
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.
|
|
void | otTcpCircularSendBufferHandleForwardProgress ( otTcpCircularSendBuffer *aSendBuffer, size_t aInSendBuffer) |
Performs circular-send-buffer-specific handling in the otTcpForwardProgress callback.
|
|
size_t | otTcpCircularSendBufferGetFreeSpace (const otTcpCircularSendBuffer *aSendBuffer) |
Returns the amount of free space in the TCP circular send buffer.
|
|
void | otTcpCircularSendBufferForceDiscardAll ( otTcpCircularSendBuffer *aSendBuffer) |
Forcibly discards all data in the circular send buffer.
|
|
otError | otTcpCircularSendBufferDeinitialize ( otTcpCircularSendBuffer *aSendBuffer) |
Deinitializes a TCP circular send buffer, detaching it if attached.
|
Detailed Description
This module includes easy-to-use abstractions on top of the base TCP API.
Typedef Documentation
◆ otTcpCircularSendBuffer
typedef struct otTcpCircularSendBuffer otTcpCircularSendBuffer |
This structure 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.
Function Documentation
◆ otTcpCircularSendBufferDeinitialize()
otError otTcpCircularSendBufferDeinitialize | ( | otTcpCircularSendBuffer * |
aSendBuffer
|
) |
Deinitializes a TCP circular send buffer, detaching it if attached.
If the TCP circular send buffer is not empty, then this operation will fail.
- Parameters
-
[in] aSendBuffer
The TCP circular send buffer to deinitialize.
- Return values
-
OT_ERROR_NONE
Successfully deinitialize the TCP circular send buffer. OT_ERROR_BUSY
Circular buffer contains data and cannot be deinitialized.
◆ otTcpCircularSendBufferForceDiscardAll()
void otTcpCircularSendBufferForceDiscardAll | ( | otTcpCircularSendBuffer * |
aSendBuffer
|
) |
Forcibly discards all data in the circular send buffer.
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.
- Parameters
-
[in] aSendBuffer
The TCP circular send buffer whose data to discard.
◆ otTcpCircularSendBufferGetFreeSpace()
size_t otTcpCircularSendBufferGetFreeSpace | ( | const otTcpCircularSendBuffer * |
aSendBuffer
|
) |
Returns the amount of free space in the TCP circular send buffer.
This operation will always succeed.
- Parameters
-
[in] aSendBuffer
A pointer to the TCP circular send buffer whose amount of free space to return.
- Returns
- The amount of free space in the send buffer.
◆ otTcpCircularSendBufferHandleForwardProgress()
void otTcpCircularSendBufferHandleForwardProgress | ( | otTcpCircularSendBuffer * |
aSendBuffer,
|
size_t |
aInSendBuffer
|
||
) |
Performs circular-send-buffer-specific handling in the otTcpForwardProgress callback.
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()
.
- Parameters
-
[in] aSendBuffer
A pointer to the TCP circular send buffer for the endpoint for which otTcpForwardProgress() was invoked. [in] aInSendBuffer
Value of aInSendBuffer
passed to the otTcpForwardProgress() callback.
◆ otTcpCircularSendBufferInitialize()
void otTcpCircularSendBufferInitialize | ( | otTcpCircularSendBuffer * |
aSendBuffer,
|
void * |
aDataBuffer,
|
||
size_t |
aCapacity
|
||
) |
Initializes a TCP circular send buffer.
- Parameters
-
[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 aDataBuffer
.
◆ 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.
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.
- Parameters
-
[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 aData
to copy into the TCP circular send buffer.[out] aWritten
Populated with the amount of data copied into the send buffer, which might be less than aLength
if the send buffer reaches capacity.[in] aFlags
Flags specifying options for this operation (see enumeration above).
- Returns
- OT_ERROR_NONE Successfully copied data into the send buffer and sent it on the TCP endpoint.
- OT_ERROR_FAILED Failed to send out data on the TCP endpoint.