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

This file contains internal definitions and implementation used with the SDK that is not part of the API. The Endpoint Manager is used to synchronize connection reset and shutdown events across all threads that are related to the connection. More...

#include "adapter_efa.h"
#include "endpoint_manager.h"
#include <arpa/inet.h>
#include "adapter_api.h"
#include "cdi_logger_api.h"
#include "cdi_os_api.h"
#include "internal.h"
#include "internal_rx.h"
#include "internal_tx.h"
#include "internal_utility.h"
#include "rx_reorder_payloads.h"
#include "statistics.h"
#include "utilities_api.h"

Data Structures

struct  InternalEndpointState
 This defines a structure that contains all the state information for endpoint state changes. More...
 
struct  EndpointManagerState
 This defines a structure that contains all the state information for endpoint state changes. More...
 

Functions

static InternalEndpointStateCdiEndpointToInternalEndpoint (CdiEndpointHandle handle)
 
static bool SetCommand (InternalEndpointState *internal_endpoint_ptr, EndpointManagerCommand command)
 
static CdiReturnStatus FlushResources (InternalEndpointState *endpoint_ptr)
 
static void DestroyEndpoint (CdiEndpointHandle handle)
 
static CDI_THREAD EndpointManagerThread (void *ptr)
 
static void IncrementThreadWaitCount (EndpointManagerState *mgr_ptr)
 
static void DecrementThreadWaitCount (EndpointManagerState *mgr_ptr)
 
static CdiReturnStatus CreateEndpointCommonResources (EndpointManagerState *mgr_ptr, InternalEndpointState **ret_internal_endpoint_ptr)
 
CdiReturnStatus EndpointManagerCreate (CdiConnectionHandle handle, CdiCoreStatsCallback stats_cb_ptr, CdiUserCbParameter stats_user_cb_param, const CdiStatsConfigData *stats_config_ptr, EndpointManagerHandle *ret_handle_ptr)
 
void EndpointManagerDestroy (EndpointManagerHandle handle)
 
EndpointManagerHandle EndpointManagerConnectionToEndpointManager (CdiConnectionHandle handle)
 
void EndpointManagerRemoteEndpointInfoSet (CdiEndpointHandle handle, const struct sockaddr_in *remote_address_ptr, const char *stream_name_str)
 
const char * EndpointManagerEndpointStreamNameGet (CdiEndpointHandle handle)
 
const char * EndpointManagerEndpointRemoteIpGet (CdiEndpointHandle handle)
 
int EndpointManagerEndpointRemotePortGet (CdiEndpointHandle handle)
 
const struct sockaddr_in * EndpointManagerEndpointRemoteAddressGet (CdiEndpointHandle handle)
 
void EndpointManagerQueueEndpointReset (CdiEndpointHandle handle)
 
void EndpointManagerQueueEndpointStart (CdiEndpointHandle handle)
 
void EndpointManagerShutdownConnection (EndpointManagerHandle handle)
 
CdiSignalType EndpointManagerThreadRegister (EndpointManagerHandle handle, const char *thread_name_str)
 
void EndpointManagerThreadWait (EndpointManagerHandle handle)
 
bool EndpointManagerIsConnectionShuttingDown (EndpointManagerHandle handle)
 
CdiSignalType EndpointManagerGetNotificationSignal (EndpointManagerHandle handle)
 
void EndpointManagerConnectionStateChange (CdiEndpointHandle handle, CdiConnectionStatus status_code, const char *error_msg_str)
 
CdiReturnStatus EndpointManagerTxCreateEndpoint (EndpointManagerHandle handle, bool is_multi_stream, const char *dest_ip_addr_str, int dest_port, const char *stream_name_str, CdiEndpointHandle *ret_endpoint_handle_ptr)
 
CdiReturnStatus EndpointManagerRxCreateEndpoint (EndpointManagerHandle handle, int dest_port, const struct sockaddr_in *source_address_ptr, const char *stream_name_str, CdiEndpointHandle *ret_endpoint_handle_ptr)
 
CdiReturnStatus EndpointManagerProtocolVersionSet (CdiEndpointHandle handle, const CdiProtocolVersionNumber *remote_version_ptr)
 Set the protocol version for the specified endpoint. The protocol version actually used is negotiated using the specified remote version and the current version of the CDI-SDK.
 
void EndpointManagerEndpointDestroy (CdiEndpointHandle handle)
 
bool EndpointManagerIsEndpoint (EndpointManagerHandle handle, CdiEndpointHandle endpoint_handle)
 
CdiEndpointHandle EndpointManagerGetFirstEndpoint (EndpointManagerHandle handle)
 
CdiEndpointHandle EndpointManagerGetNextEndpoint (CdiEndpointHandle handle)
 
AdapterEndpointHandle EndpointManagerEndpointToAdapterEndpoint (CdiEndpointHandle handle)
 
int EndpointManagerEndpointGetCount (EndpointManagerHandle handle)
 
bool EndpointManagerPoll (CdiEndpointHandle *handle_ptr)
 
bool EndpointManagerPollThreadExit (EndpointManagerHandle handle)
 

Detailed Description

This file contains internal definitions and implementation used with the SDK that is not part of the API. The Endpoint Manager is used to synchronize connection reset and shutdown events across all threads that are related to the connection.

Function Documentation

◆ CdiEndpointToInternalEndpoint()

static InternalEndpointState * CdiEndpointToInternalEndpoint ( CdiEndpointHandle handle)
static

Convert an CDI endpoint handle into and internal endpoint state structure (InternalEndpointState).

Parameters
handleCDI Endpoint handle
Returns
Pointer to internal endpoint state structure.

◆ CreateEndpointCommonResources()

static CdiReturnStatus CreateEndpointCommonResources ( EndpointManagerState * mgr_ptr,
InternalEndpointState ** ret_internal_endpoint_ptr )
static

Create resources common to both Tx and Rx endpoints.

Parameters
mgr_ptrPointer to Endpoint Manager.
ret_internal_endpoint_ptrAddress where to write returned endpoint handle.
Returns
kCdiStatusOk if successful, otherwise a value that indicates the nature of the failure is returned.

◆ DecrementThreadWaitCount()

static void DecrementThreadWaitCount ( EndpointManagerState * mgr_ptr)
static

Decrement the thread wait counter. If the count reaches zero, the state of signals will be changed so additional state change commands can be processed by EndpointManagerThread().

Parameters
mgr_ptrPointer to Endpoint Manager state data.

◆ DestroyEndpoint()

static void DestroyEndpoint ( CdiEndpointHandle handle)
static

Destroy an endpoint, closing its adapter endpoint and freeing resources used by it.

Parameters
handleHandle of endpoint to destroy.

◆ EndpointManagerConnectionStateChange()

void EndpointManagerConnectionStateChange ( CdiEndpointHandle handle,
CdiConnectionStatus status_code,
const char * error_msg_str )

Notify the application of a connection state change using the user registered connection callback function, if the state has actually changed.

NOTE: This function is called from ProbeControlThread().

Parameters
handleHandle of endpoint.
status_codeConnection status code (connected or disconnected).
error_msg_strPointer to optional error message string to provide to the user registered callback function.

◆ EndpointManagerConnectionToEndpointManager()

EndpointManagerHandle EndpointManagerConnectionToEndpointManager ( CdiConnectionHandle handle)

Return the Endpoint Manager associated with the specified connection.

Parameters
handleHandle of the connection.
Returns
Endpoint Manager handle.

◆ EndpointManagerCreate()

CdiReturnStatus EndpointManagerCreate ( CdiConnectionHandle handle,
CdiCoreStatsCallback stats_cb_ptr,
CdiUserCbParameter stats_user_cb_param,
const CdiStatsConfigData * stats_config_ptr,
EndpointManagerHandle * ret_handle_ptr )

Create an instance of the Endpoint Manager for the specified connection.

Parameters
handleHandle of connection.
stats_cb_ptrAddress of stats callback function.
stats_user_cb_paramUser-defined parameter in structure passed to stats_cb_ptr.
stats_config_ptrPointer to statistics configuration data.
ret_handle_ptrAddress where to write returned Endpoint Manager handle.
Returns
kCdiStatusOk if the operation was successful or a value that indicates the nature of the failure.

◆ EndpointManagerDestroy()

void EndpointManagerDestroy ( EndpointManagerHandle handle)

Destroys the resources used by the instance of the specified Endpoint Manager.

Parameters
handleHandle of Endpoint Manager.

◆ EndpointManagerEndpointDestroy()

void EndpointManagerEndpointDestroy ( CdiEndpointHandle handle)

Destroy the specified endpoint. Thread will block until the endpoint is destroyed by EndpointManagerPoll().

Parameters
handleHandle of CDI endpoint.

◆ EndpointManagerEndpointGetCount()

int EndpointManagerEndpointGetCount ( EndpointManagerHandle handle)

Return the number of endpoints associated with the specified Endpoint Manager.

Parameters
handleHandle of Endpoint Manager.
Returns
Number of endpoints.

◆ EndpointManagerEndpointRemoteAddressGet()

const struct sockaddr_in * EndpointManagerEndpointRemoteAddressGet ( CdiEndpointHandle handle)

Get the remote address structure (sockaddr_in) related to the provided endpoint.

Parameters
handleHandle of endpoint.
Returns
Pointer to remote address structure.

◆ EndpointManagerEndpointRemoteIpGet()

const char * EndpointManagerEndpointRemoteIpGet ( CdiEndpointHandle handle)

Get the remote IP address related to the provided endpoint.

Parameters
handleHandle of endpoint.
Returns
Pointer to IP address string.

◆ EndpointManagerEndpointRemotePortGet()

int EndpointManagerEndpointRemotePortGet ( CdiEndpointHandle handle)

Get the remote port related to the provided endpoint.

Parameters
handleHandle of endpoint.
Returns
Remote port as integer value.

◆ EndpointManagerEndpointStreamNameGet()

const char * EndpointManagerEndpointStreamNameGet ( CdiEndpointHandle handle)

Get the stream name related to the provided endpoint. If the stream name empty, then NULL is returned.

Parameters
handleHandle of endpoint.
Returns
Pointer to stream name or NULL if empty.

◆ EndpointManagerEndpointToAdapterEndpoint()

AdapterEndpointHandle EndpointManagerEndpointToAdapterEndpoint ( CdiEndpointHandle handle)

Return the adapter endpoint related to the specified CDI endpoint.

Parameters
handleHandle of CDI endpoint.
Returns
Handle of adapter endpoint.

◆ EndpointManagerGetFirstEndpoint()

CdiEndpointHandle EndpointManagerGetFirstEndpoint ( EndpointManagerHandle handle)

Returns the first endpoint in the list of endpoints associated with the specified Endpoint Manager.

Parameters
handleHandle of CDI Endpoint Manager.
Returns
Handle of first endpoint in the list. Returns NULL if the list is empty.

◆ EndpointManagerGetNextEndpoint()

CdiEndpointHandle EndpointManagerGetNextEndpoint ( CdiEndpointHandle handle)

Returns the next endpoint in the list of endpoints associated with the specified CDI endpoint.

Parameters
handleHandle of CDI endpoint.
Returns
Handle of next endpoint in the list. Returns NULL if no more endpoints.

◆ EndpointManagerGetNotificationSignal()

CdiSignalType EndpointManagerGetNotificationSignal ( EndpointManagerHandle handle)

Return the signal that is used to notify registered threads that they must call EndpointManagerThreadWait() so a queued state change can be processed.

Parameters
handleHandle of endpoint.
Returns
Returns the notification signal.

◆ EndpointManagerIsConnectionShuttingDown()

bool EndpointManagerIsConnectionShuttingDown ( EndpointManagerHandle handle)

Return true if the connection is in the process of being shutdown.

Parameters
handleHandle of Endpoint Manager.
Returns
Returns true if the connection is in the process of being shutdown, otherwise false is returned.

◆ EndpointManagerIsEndpoint()

bool EndpointManagerIsEndpoint ( EndpointManagerHandle handle,
CdiEndpointHandle endpoint_handle )

Returns true if the specified endpoint exists within the specified Endpoint Manager.

Parameters
handleHandle of CDI Endpoint Manager.
endpoint_handleHandle of CDI endpoint.
Returns
Handle of first endpoint in the list. Returns NULL if the list is empty.

◆ EndpointManagerPoll()

bool EndpointManagerPoll ( CdiEndpointHandle * handle_ptr)

Perform Endpoint Manager polling and determine if adapter level poll APIs should be used or not.

Parameters
handle_ptrOn entry, Address to handle of endpoint. On exit, handle of next endpoint is written to to address.
Returns
true if poll thread should invoke adapter poll APIs, false if it should not.

◆ EndpointManagerPollThreadExit()

bool EndpointManagerPollThreadExit ( EndpointManagerHandle handle)

Called by poll thread when it is about to exit. Must continue to call this as part of the polling cycle until true is returned.

Parameters
handleHandle of Endpoint Manager.
Returns
true if ok to exit.

◆ EndpointManagerProtocolVersionSet()

CdiReturnStatus EndpointManagerProtocolVersionSet ( CdiEndpointHandle handle,
const CdiProtocolVersionNumber * remote_version_ptr )

Set the protocol version for the specified endpoint. The protocol version actually used is negotiated using the specified remote version and the current version of the CDI-SDK.

Parameters
handleHandle of CDI endpoint.
remote_version_ptrPointer to remote protocol version data.
Returns
kCdiStatusOk if the operation was successful or a value that indicates the nature of the failure.

◆ EndpointManagerQueueEndpointReset()

void EndpointManagerQueueEndpointReset ( CdiEndpointHandle handle)

Queue a request to reset the endpoint associated with the specified Endpoint Manager.

Parameters
handleHandle of endpoint.

◆ EndpointManagerQueueEndpointStart()

void EndpointManagerQueueEndpointStart ( CdiEndpointHandle handle)

Queue a request to start the endpoint associated with the specified Endpoint Manager.

Parameters
handleHandle of endpoint.

◆ EndpointManagerRemoteEndpointInfoSet()

void EndpointManagerRemoteEndpointInfoSet ( CdiEndpointHandle handle,
const struct sockaddr_in * remote_address_ptr,
const char * stream_name_str )

Copy the specified information about the remote endpoint to the internal state data of the provided endpoint.

Parameters
handleHandle of endpoint.
remote_address_ptrPointer to remote address (sockaddr_in)
stream_name_strPointer to endpoint stream name. If the stream name is NULL, then a '\0' will be stored.

◆ EndpointManagerRxCreateEndpoint()

CdiReturnStatus EndpointManagerRxCreateEndpoint ( EndpointManagerHandle handle,
int dest_port,
const struct sockaddr_in * source_address_ptr,
const char * stream_name_str,
CdiEndpointHandle * ret_endpoint_handle_ptr )

Create resources used for a new Rx endpoint and add it to the list of endpoints managed by the specified Endpoint Manager.

Parameters
handleHandle of Endpoint Manager.
dest_portDestination port.
source_address_ptrPointer to source address (from the sender).
stream_name_strPointer to stream name string.
ret_endpoint_handle_ptrAddress where to write the handle of the new endpoint.
Returns
kCdiStatusOk if the operation was successful or a value that indicates the nature of the failure.

◆ EndpointManagerShutdownConnection()

void EndpointManagerShutdownConnection ( EndpointManagerHandle handle)

Shutdown the connection associated with the specified Endpoint Manager. This will block until threads registered using EndpointManagerThreadRegister() have called EndpointManagerThreadWait() and the connection shutdown has completed.

Parameters
handleHandle of Endpoint Manager.

◆ EndpointManagerThread()

static CDI_THREAD EndpointManagerThread ( void * ptr)
static

Thread used to manage endpoint reset, start and shutdown events.

Parameters
ptrPointer to Endpoint Manager state data.
Returns
The return value is not used.

◆ EndpointManagerThreadRegister()

CdiSignalType EndpointManagerThreadRegister ( EndpointManagerHandle handle,
const char * thread_name_str )

Register a thread with the specified Endpoint Manager. This should be called once, at the start of each thread that uses resources associated with the connection. The Endpoint Manager keeps track of how many times this function is used (how many threads). When the Endpoint Manager receives a request via one of the Queue API functions, it will wait until the number of threads have called EndpointManagerThreadWait() and are blocked. Then, it can carry out the request and unblock the waiting threads after the request has completed.

Parameters
handleHandle of Endpoint Manager.
thread_name_strName of thread.
Returns
Returns the notification signal. Same value returned from EndpointManagerGetNotificationSignal().

◆ EndpointManagerThreadWait()

void EndpointManagerThreadWait ( EndpointManagerHandle handle)

For all threads that have used EndpointManagerThreadRegister(), each must call this function whenever the signal obtained using EndpointManagerGetNotificationSignal() is set (it is set whenever one of the Queue API functions are used). This will block the thread until all registered threads have called this function. The threads are blocked until the pending state change request has completed.

Parameters
handleHandle of Endpoint Manager.

◆ EndpointManagerTxCreateEndpoint()

CdiReturnStatus EndpointManagerTxCreateEndpoint ( EndpointManagerHandle handle,
bool is_multi_stream,
const char * dest_ip_addr_str,
int dest_port,
const char * stream_name_str,
CdiEndpointHandle * ret_endpoint_handle_ptr )

Create resources used for a new Tx endpoint and add it to the list of endpoints managed by the specified Endpoint Manager.

Parameters
handleHandle of Endpoint Manager.
is_multi_streamTrue if the Tx endpoint is going to be used by multiple Tx streams.
dest_ip_addr_strPointer to destination IP address string.
dest_portDestination port.
stream_name_strPointer to stream name string.
ret_endpoint_handle_ptrAddress where to write the handle of the new endpoint.
Returns
kCdiStatusOk if the operation was successful or a value that indicates the nature of the failure.

◆ FlushResources()

static CdiReturnStatus FlushResources ( InternalEndpointState * endpoint_ptr)
static

Flush resources associated with the specified connection.

Parameters
endpoint_ptrPointer to endpoint to free resources.
Returns
Status code indicating success or failure.

◆ IncrementThreadWaitCount()

static void IncrementThreadWaitCount ( EndpointManagerState * mgr_ptr)
static

Increment the thread wait counter. If the count matches the number of threads registered to wait, a signal will be set to wakeup EndpointManagerThread() so it can process pending endpoint state changes.

Parameters
mgr_ptrPointer to Endpoint Manager state data.

◆ SetCommand()

static bool SetCommand ( InternalEndpointState * internal_endpoint_ptr,
EndpointManagerCommand command )
static

Add a new command to the endpoint queue to be processed by EndpointManagerThread().

Parameters
internal_endpoint_ptrPointer to internal endpoint structure to queue new command.
commandNew command to add to the queue.
Returns
True if command placed in queue, otherwise false is returned.