CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
internal_rx.c File Reference

This file contains internal definitions and implementation used with the SDK that is not part of the API. More...

#include "internal_rx.h"
#include <string.h>
#include "adapter_api.h"
#include "cdi_logger_api.h"
#include "cdi_pool_api.h"
#include "endpoint_manager.h"
#include "internal.h"
#include "private.h"
#include "private_avm.h"
#include "receive_buffer.h"
#include "rx_reorder_packets.h"
#include "rx_reorder_payloads.h"
#include "statistics.h"

Macros

#define SIZE_OF_CDI_PACKET_AVM_WITH_CONFIG_SDK_1   (58)
 Size of CDIPacketAvmWithConfig structure used in SDK 1.x.x.
 

Functions

static void SetCbErrorAndFreeResources (CdiReturnStatus rs, const char *error_msg_str, CdiCoreCbData *core_cb_data_ptr, CdiSgList *payload_sgl_ptr)
 
static void UpdatePayloadStats (CdiEndpointState *endpoint_ptr, RxPayloadWorkRequestState *work_request_ptr)
 
static void InvokeRawPayloadCallback (CdiConnectionState *con_state_ptr, AppPayloadCallbackData *app_cb_data_ptr, CdiCoreCbData *core_cb_data_ptr)
 
static void InvokeAvmPayloadCallback (CdiConnectionState *con_state_ptr, AppPayloadCallbackData *app_cb_data_ptr, CdiCoreCbData *core_cb_data_ptr)
 
static void UpdateApplicationCallbackDataFromCdiPacket0 (AppPayloadCallbackData *app_payload_cb_data_ptr, const CdiDecodedPacketNum0Info *num0_info_ptr)
 
static void UpdatePayloadStateDataFromCDIPacket0 (RxPayloadState *payload_state_ptr, CdiDecodedPacketHeader *header_ptr)
 
static bool InitializePayloadState (CdiProtocolHandle protocol_handle, CdiEndpointState *endpoint_ptr, const Packet *packet_ptr, RxPayloadState *payload_state_ptr, CdiDecodedPacketHeader *header_ptr, CdiMemoryState **payload_memory_state_ptr)
 
static bool CopyToLinearBuffer (CdiConnectionState *con_state_ptr, const Packet *packet_ptr, RxPayloadState *payload_state_ptr, const CdiDecodedPacketHeader *header_ptr)
 
static void FreeMemoryState (CdiSgList *sgl_ptr)
 
static void FreePayloadBuffer (CdiSgList *sgl_ptr)
 
static bool FinalizePayload (CdiConnectionState *con_state_ptr, RxPayloadState *payload_state_ptr)
 
static void QueueBackPressurePayloadToApp (CdiConnectionState *con_state_ptr, CdiEndpointState *endpoint_ptr, const CdiDecodedPacketHeader *decoded_header_ptr)
 
CdiReturnStatus RxCreateInternal (CdiConnectionProtocolType protocol_type, CdiRxConfigData *config_data_ptr, CdiCallback rx_cb_ptr, CdiConnectionHandle *ret_handle_ptr)
 
CdiReturnStatus RxEndpointCreateDynamicPools (CdiEndpointHandle handle)
 Create dynamically allocated memory pools for the specified endpoint.
 
void RxEndpointFlushResources (CdiEndpointState *endpoint_ptr)
 
void RxConnectionDestroyInternal (CdiConnectionHandle con_handle)
 
void RxEndpointDestroy (CdiEndpointHandle handle)
 
void RxPacketReceive (void *param_ptr, Packet *packet_ptr, EndpointMessageType message_type)
 
void RxSendPayload (CdiEndpointState *endpoint_ptr, RxPayloadState *payload_state_ptr)
 
void RxFreePayloadResources (CdiEndpointState *endpoint_ptr, RxPayloadState *payload_state_ptr, bool free_memory_state)
 
void RxInvokeAppPayloadCallback (CdiConnectionState *con_state_ptr, AppPayloadCallbackData *app_cb_data_ptr)
 
CdiReturnStatus RxEnqueueFreeBuffer (const CdiSgList *sgl_ptr)
 
bool RxPollFreeBuffer (void *param_ptr, CdiSgList *ret_packet_buffer_sgl_ptr)
 

Detailed Description

This file contains internal definitions and implementation used with the SDK that is not part of the API.

Function Documentation

◆ CopyToLinearBuffer()

static bool CopyToLinearBuffer ( CdiConnectionState * con_state_ptr,
const Packet * packet_ptr,
RxPayloadState * payload_state_ptr,
const CdiDecodedPacketHeader * header_ptr )
static

Copy the packet payloads's contents to its proper location within the current linear receive payload buffer. It takes into account the case of packets with a data offset in the case where a packet's size somewhere in the payload was reduced to limit the number of SGL entries required.

Parameters
con_state_ptrPointer to connection state structure.
packet_ptrPointer to packet whose contents are to be copied.
payload_state_ptrPointer to payload structure being updated.
header_ptrPointer to CDI header that contains data to be added to payload state.
Returns
true if the function completed successfully, false if a problem was encountered.

◆ FinalizePayload()

static bool FinalizePayload ( CdiConnectionState * con_state_ptr,
RxPayloadState * payload_state_ptr )
static

Finalizes the payload state. Call this once all data expected for the payload has been received.

Parameters
con_state_ptrPointer to connection state structure.
payload_state_ptrPointer to payload structure being updated.
Returns
Returns true if payload successfully received without any packet reorder issues, otherwise false is returned.

◆ FreeMemoryState()

static void FreeMemoryState ( CdiSgList * sgl_ptr)
static

Free payload memory state.

Parameters
sgl_ptrPointer to payload scatter-gather list.

◆ FreePayloadBuffer()

static void FreePayloadBuffer ( CdiSgList * sgl_ptr)
static

Free resources specific to a payload. Adapter packet resources are freed separately.

Parameters
sgl_ptrPointer to payload scatter-gather list.

◆ InitializePayloadState()

static bool InitializePayloadState ( CdiProtocolHandle protocol_handle,
CdiEndpointState * endpoint_ptr,
const Packet * packet_ptr,
RxPayloadState * payload_state_ptr,
CdiDecodedPacketHeader * header_ptr,
CdiMemoryState ** payload_memory_state_ptr )
static

Initializes the state data for a payload. Call this when the first packet of a payload is received.

Parameters
protocol_handleHandle to protocol being used.
endpoint_ptrPointer to endpoint state structure.
packet_ptrPointer to the first packet received for a given payload.
payload_state_ptrPointer to payload structure being updated.
header_ptrPointer to decoded packet header.
payload_memory_state_ptrPointer to location to write the address of a pool allocated CdiMemoryState structure.
Returns
true if this function completed successfully, false if a problem was encountered.

◆ InvokeAvmPayloadCallback()

static void InvokeAvmPayloadCallback ( CdiConnectionState * con_state_ptr,
AppPayloadCallbackData * app_cb_data_ptr,
CdiCoreCbData * core_cb_data_ptr )
static

Call the AVM payload user-registered callback function.

Parameters
con_state_ptrPointer to connection state data.
app_cb_data_ptrPointer to application callback data.
core_cb_data_ptrPointer to core callback data.

◆ InvokeRawPayloadCallback()

static void InvokeRawPayloadCallback ( CdiConnectionState * con_state_ptr,
AppPayloadCallbackData * app_cb_data_ptr,
CdiCoreCbData * core_cb_data_ptr )
static

Call the Raw payload user-registered callback function.

Parameters
con_state_ptrPointer to connection state data.
app_cb_data_ptrPointer to application callback data.
core_cb_data_ptrPointer to core callback data.

◆ QueueBackPressurePayloadToApp()

static void QueueBackPressurePayloadToApp ( CdiConnectionState * con_state_ptr,
CdiEndpointState * endpoint_ptr,
const CdiDecodedPacketHeader * decoded_header_ptr )
static

Queue back pressure payload to application.

Parameters
con_state_ptrPointer to connection state data.
endpoint_ptrPointer to endpoint data.
decoded_header_ptrPointer to decoded packet header.

◆ RxConnectionDestroyInternal()

void RxConnectionDestroyInternal ( CdiConnectionHandle con_handle)

◆ RxCreateInternal()

CdiReturnStatus RxCreateInternal ( CdiConnectionProtocolType protocol_type,
CdiRxConfigData * config_data_ptr,
CdiCallback rx_cb_ptr,
CdiConnectionHandle * ret_handle_ptr )

Create a raw receiver connection.

Parameters
protocol_typeSpecifies the protocol for payload (E.g. RAW or AVM)
config_data_ptrAddress of a structure with all of the parameters to use for setting up the connection.
rx_cb_ptrThe address of a function which will be called whenever a payload is received from the remote host.
ret_handle_ptrAn address which will receive the handle of the newly created connection.
Returns
kCdiStatusOk if the connection was successfully created, otherwise a value indicating why it failed.

◆ RxEndpointCreateDynamicPools()

CdiReturnStatus RxEndpointCreateDynamicPools ( CdiEndpointHandle handle)

Create dynamically allocated memory pools for the specified endpoint.

Parameters
handleHandle of endpoint to create dynamic memory pools.
Returns
kCdiStatusOk if the connection was successfully created, otherwise a value indicating why it failed.

◆ RxEndpointDestroy()

void RxEndpointDestroy ( CdiEndpointHandle handle)

Destroy resources associated with the specified endpoint.

Parameters
handleHandle of endpoint to destroy.

◆ RxEndpointFlushResources()

void RxEndpointFlushResources ( CdiEndpointState * endpoint_ptr)

Flush resources associated with Rx. NOTE: This function should only be called after the thread has been paused using EndpointManagerThreadWait().

Parameters
endpoint_ptrPointer to endpoint to free resources.

◆ RxEnqueueFreeBuffer()

CdiReturnStatus RxEnqueueFreeBuffer ( const CdiSgList * sgl_ptr)

Enqueue to free the receive buffer.

Parameters
sgl_ptrThe scatter-gather list containing the memory to be freed.
Returns
kCdiStatusOk if the connection was successfully created, otherwise a value indicating why it failed.

◆ RxFreePayloadResources()

void RxFreePayloadResources ( CdiEndpointState * endpoint_ptr,
RxPayloadState * payload_state_ptr,
bool free_memory_state )

Free payload resources.

Parameters
endpoint_ptrPointer to connection state structure.
payload_state_ptrPointer to payload structure being updated.
free_memory_state

◆ RxInvokeAppPayloadCallback()

void RxInvokeAppPayloadCallback ( CdiConnectionState * con_state_ptr,
AppPayloadCallbackData * app_cb_data_ptr )

Invoke the user registered Rx callback function for a payload.

Parameters
con_state_ptrPointer to connection state data.
app_cb_data_ptrPointer to application callback data.

◆ RxPacketReceive()

void RxPacketReceive ( void * param_ptr,
Packet * packet_ptr,
EndpointMessageType message_type )

A packet has been received by the receiver. Need to reassemble it into a payload and send the payload SGL to the application.

Parameters
param_ptrPointer to connection that the packet was received on as a void*.
packet_ptrPointer to the received packet.
message_typeEndpoint message type.

◆ RxPollFreeBuffer()

bool RxPollFreeBuffer ( void * param_ptr,
CdiSgList * ret_packet_buffer_sgl_ptr )

Called from PollThread() in the adapter to poll if any Rx buffers need to be freed. If there are any, this function will free payload level resources and then return a list of adapter packet buffer SGLs that need to be freed by the caller.

Parameters
param_ptrA pointer to data used by the function.
ret_packet_buffer_sgl_ptrPointer to address where to write the returned packet buffer SGL that needs to be freed by the caller.
Returns
Returns true if an adapter buffer SGL is being returned.

◆ RxSendPayload()

void RxSendPayload ( CdiEndpointState * endpoint_ptr,
RxPayloadState * send_payload_state_ptr )

Send the payload on to the next stage because it is complete or determined to be in error.

Parameters
endpoint_ptrPointer to endpoint state structure.
send_payload_state_ptrPointer to the payload state for the completed payload.

◆ SetCbErrorAndFreeResources()

static void SetCbErrorAndFreeResources ( CdiReturnStatus rs,
const char * error_msg_str,
CdiCoreCbData * core_cb_data_ptr,
CdiSgList * payload_sgl_ptr )
static

Function to set status code and optional error message string in the core callback and frees any receive buffer resources.

Parameters
rsReturn status code.
error_msg_strPointer to optional error message string.
core_cb_data_ptrPointer to the core callback data structure.
payload_sgl_ptrPointer to the payload SGL list to free.

◆ UpdateApplicationCallbackDataFromCdiPacket0()

static void UpdateApplicationCallbackDataFromCdiPacket0 ( AppPayloadCallbackData * app_payload_cb_data_ptr,
const CdiDecodedPacketNum0Info * num0_info_ptr )
static

Update application callback data with header packet sequence number 0.

Parameters
app_payload_cb_data_ptrAddress where to write the application callback data.
num0_info_ptrPointer to CDI header for packet sequence number 0.

◆ UpdatePayloadStateDataFromCDIPacket0()

static void UpdatePayloadStateDataFromCDIPacket0 ( RxPayloadState * payload_state_ptr,
CdiDecodedPacketHeader * header_ptr )
static

Update payload state when header packet sequence number 0 arrives.

Parameters
payload_state_ptrPointer to payload structure being updated.
header_ptrPointer to CDI header that contains data to be added to payload state.

◆ UpdatePayloadStats()

static void UpdatePayloadStats ( CdiEndpointState * endpoint_ptr,
RxPayloadWorkRequestState * work_request_ptr )
static

Update payload statistics data whenever a payload has either been successfully received or an error occurred while being received.

Parameters
endpoint_ptrPointer to endpoint state data.
work_request_ptrPointer to work request data.