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

This file contains definitions and functions for the socket adapter. More...

#include "adapter_api.h"
#include <sys/uio.h>
#include "cdi_os_api.h"
#include "internal.h"
#include "internal_log.h"
#include "private.h"
#include "protocol.h"

Data Structures

struct  ReceiveBufferRecord
 Definition of memory space where rx data is placed. More...
 
struct  SocketEndpointState
 State definition for socket endpoint. More...
 

Macros

#define kSocketMtu   (1500 - 0x2a)
 Ethernet frame size less MAC/IP/UDP headers.
 

Functions

static CdiReturnStatus SocketConnectionCreate (AdapterConnectionHandle handle, int port_number, const char *bind_ip_addr_str)
 Forward declaration of function.
 
static CdiReturnStatus SocketConnectionDestroy (AdapterConnectionHandle handle)
 Forward declaration of function.
 
static CdiReturnStatus SocketEndpointOpen (AdapterEndpointHandle endpoint, const char *remote_address_str, int port_number, const char *bind_ip_addr_str)
 Forward declaration of function.
 
static CdiReturnStatus SocketEndpointClose (AdapterEndpointHandle handle)
 Forward declaration of function.
 
static CdiReturnStatus SocketEndpointSend (const AdapterEndpointHandle handle, const Packet *packet_ptr, bool flush_packets)
 Forward declaration of function.
 
static CdiReturnStatus SocketEndpointRxBuffersFree (const AdapterEndpointHandle handle, const CdiSgList *sgl_ptr)
 Forward declaration of function.
 
static CdiReturnStatus SocketEndpointGetPort (const AdapterEndpointHandle handle, int *ret_port_number_ptr)
 Forward declaration of function.
 
static CdiReturnStatus SocketAdapterShutdown (CdiAdapterHandle adapter)
 Forward declaration of function.
 
static EndpointTransmitQueueLevel SocketGetTransmitQueueLevel (AdapterEndpointHandle handle)
 
static CDI_THREAD SocketReceiveThread (void *arg)
 
static bool SocketEndpointPoolItemInit (const void *context_ptr, void *item_ptr)
 
CdiReturnStatus SocketNetworkAdapterInitialize (CdiAdapterState *adapter_state_ptr)
 

Variables

static struct AdapterVirtualFunctionPtrTable socket_endpoint_functions
 Define the virtual table API interface for this adapter.
 

Detailed Description

This file contains definitions and functions for the socket adapter.

Function Documentation

◆ SocketAdapterShutdown()

static CdiReturnStatus SocketAdapterShutdown ( CdiAdapterHandle adapter)
static

Forward declaration of function.

Shuts down the adapter, freeing any resources associated with it.

Parameters
adapterThe handle of the adapter which is to be shut down.
Returns
CdiReturnStatus kCdiStatusOk always.

◆ SocketEndpointClose()

static CdiReturnStatus SocketEndpointClose ( AdapterEndpointHandle endpoint_handle)
static

Forward declaration of function.

Closes the endpoint and frees any resources associated with it.

Parameters
endpoint_handleThe handle of the endpoint to be closed.
Returns
kCdiStatusFatal if shutting down the endpoint failed, otherwise kCdiStatusOk.

◆ SocketEndpointGetPort()

static CdiReturnStatus SocketEndpointGetPort ( const AdapterEndpointHandle handle,
int * ret_port_number_ptr )
static

Forward declaration of function.

Returns the destination port number associated with the specified endpoint.

Parameters
handleThe handle of the endpoint whose port number is of interest.
ret_port_number_ptrAddress of the location where the port number is to be written.
Returns
CdiReturnStatus kCdiStatusGetPortFailed if the port number could not be ascertained or kCdiStatusOk if the port number was written to the specified address.

◆ SocketEndpointOpen()

static CdiReturnStatus SocketEndpointOpen ( AdapterEndpointHandle endpoint_handle,
const char * remote_address_str,
int port_number,
const char * bind_address_str )
static

Forward declaration of function.

Open a socket endpoint using the specified adapter.

Parameters
endpoint_handleHandle of adapter endpoint to open.
remote_address_strPointer to remote target's IP address string.
port_numberDestination port to use.
bind_address_strPointer to optional bind IP address string.
Returns
kCdiStatusOk if successful, otherwise a value that indicates the nature of the failure is returned.

◆ SocketEndpointPoolItemInit()

static bool SocketEndpointPoolItemInit ( const void * context_ptr,
void * item_ptr )
static

Initialization function for socket pool item.

Parameters
context_ptrUnused, reserve for future use.
item_ptrPointer to item being initialized.
Returns
true always

◆ SocketEndpointRxBuffersFree()

static CdiReturnStatus SocketEndpointRxBuffersFree ( const AdapterEndpointHandle handle,
const CdiSgList * sgl_ptr )
static

Forward declaration of function.

Returns the SGL entries contained in the supplied SGL to their free pool.

Parameters
handleThe endpoint to which the SGL entries belong.
sgl_ptrPointer to the SGL that contains the entries to be freed.
Returns
CdiReturnStatus kCdiStatusOk always.

◆ SocketEndpointSend()

static CdiReturnStatus SocketEndpointSend ( const AdapterEndpointHandle handle,
const Packet * packet_ptr,
bool flush_packets )
static

Forward declaration of function.

Sends a packet to the destination of the endpoint.

Parameters
handleThe handle of the endpoint on which to send the packet.
packet_ptrA pointer to the packet data to be sent to the remote endpoint.
flush_packetstrue if this packet and any that might be queued to be sent should be sent immediately or false if this packet can wait in the queue. The socket adapter does not queue packets so this argument is ignored and always treated as true.
Returns
CdiReturnStatus kCdiStatusOk if the packet was sent or kCdiStatusSendFailed if the writing to the socket failed.

◆ SocketGetTransmitQueueLevel()

static EndpointTransmitQueueLevel SocketGetTransmitQueueLevel ( AdapterEndpointHandle handle)
static

Returns the adapter endpoint's transmit queue level which is always kEndpointTransmitQueueNa for this type.

Parameters
handleThe handle of the adapter endpoint to query.
Returns
kEndpointTransmitQueueNa always.

◆ SocketNetworkAdapterInitialize()

CdiReturnStatus SocketNetworkAdapterInitialize ( CdiAdapterState * adapter_state_ptr)

Initializes socket based adapter specified by the values in the provided CdiAdapterState structure.

Parameters
adapter_state_ptrThe address of the generic adapter state preinitialized with the generic values including the CdiAdapterData structure which contains the values provided to the SDK by the user program.
Returns
CdiReturnStatus kCdiStausOk if successful, otherwise a value indicating the nature of failure.

◆ SocketReceiveThread()

static CDI_THREAD SocketReceiveThread ( void * arg)
static

Thread to receive packets over socket.

Parameters
argPointer to thread.
Returns
Return value not used.

Variable Documentation

◆ socket_endpoint_functions

struct AdapterVirtualFunctionPtrTable socket_endpoint_functions
static
Initial value:
= {
.CreateConnection = SocketConnectionCreate,
.DestroyConnection = SocketConnectionDestroy,
.Poll = NULL,
.GetTransmitQueueLevel = SocketGetTransmitQueueLevel,
.RxBuffersFree = SocketEndpointRxBuffersFree,
.Reset = NULL,
.Start = NULL,
.Shutdown = SocketAdapterShutdown,
}
static CdiReturnStatus SocketAdapterShutdown(CdiAdapterHandle adapter)
Forward declaration of function.
Definition adapter_socket.c:496
static CdiReturnStatus SocketEndpointGetPort(const AdapterEndpointHandle handle, int *ret_port_number_ptr)
Forward declaration of function.
Definition adapter_socket.c:478
static EndpointTransmitQueueLevel SocketGetTransmitQueueLevel(AdapterEndpointHandle handle)
Definition adapter_socket.c:57
static CdiReturnStatus SocketEndpointOpen(AdapterEndpointHandle endpoint, const char *remote_address_str, int port_number, const char *bind_ip_addr_str)
Forward declaration of function.
Definition adapter_socket.c:230
static CdiReturnStatus SocketEndpointClose(AdapterEndpointHandle handle)
Forward declaration of function.
Definition adapter_socket.c:347
static CdiReturnStatus SocketEndpointRxBuffersFree(const AdapterEndpointHandle handle, const CdiSgList *sgl_ptr)
Forward declaration of function.
Definition adapter_socket.c:452
static CdiReturnStatus SocketConnectionCreate(AdapterConnectionHandle handle, int port_number, const char *bind_ip_addr_str)
Forward declaration of function.
Definition adapter_socket.c:196
static CdiReturnStatus SocketConnectionDestroy(AdapterConnectionHandle handle)
Forward declaration of function.
Definition adapter_socket.c:213
static CdiReturnStatus SocketEndpointSend(const AdapterEndpointHandle handle, const Packet *packet_ptr, bool flush_packets)
Forward declaration of function.
Definition adapter_socket.c:394

Define the virtual table API interface for this adapter.