Libtrap: Internal development docs  1.16.1
Data Structures | Typedefs | Functions
Collaboration diagram for TCPIP input IFC:

Data Structures

struct  tcpip_receiver_private_s
 

Typedefs

typedef struct tcpip_receiver_private_s tcpip_receiver_private_t
 

Functions

static int receive_part (void *priv, void **data, uint32_t *size, struct timeval *tm)
 
static uint64_t get_cur_timestamp ()
 
int tcpip_receiver_recv (void *priv, void *data, uint32_t *size, int timeout)
 Receive data from interface. More...
 
void tcpip_receiver_terminate (void *priv)
 Set interface state as terminated. More...
 
void tcpip_receiver_destroy (void *priv)
 Destructor of TCPIP receiver (input ifc) More...
 
static void tcpip_receiver_create_dump (void *priv, uint32_t idx, const char *path)
 
char * tcpip_recv_ifc_get_id (void *priv)
 
uint8_t tcpip_recv_ifc_is_conn (void *priv)
 
int create_tcpip_receiver_ifc (trap_ctx_priv_t *ctx, char *params, trap_input_ifc_t *ifc, uint32_t idx, enum tcpip_ifc_sockettype type)
 Constructor of input TCP/IP IFC module. This function is called by TRAP library to initialize one input interface. More...
 
static int wait_for_connection (int sock, struct timeval *tv)
 
static void client_socket_disconnect (void *priv)
 
static int client_socket_connect (void *priv, const char *dest_addr, const char *dest_port, int *socket_descriptor, struct timeval *tv)
 client_socket is used as a receiver More...
 

Detailed Description

Typedef Documentation

◆ tcpip_receiver_private_t

Function Documentation

◆ client_socket_connect()

static int client_socket_connect ( void *  priv,
const char *  dest_addr,
const char *  dest_port,
int *  socket_descriptor,
struct timeval *  tv 
)
static

client_socket is used as a receiver

Parameters
[in]privpointer to module private data
[in]dest_addrdestination address where to connect and where receive
[in]dest_portdestination port where to connect and where receive
[out]socket_descriptorsocket descriptor of established connection
[in]tvtimeout
Returns
TRAP_E_OK on success

Input interface negotiation

Definition at line 804 of file ifc_tcpip.c.

◆ client_socket_disconnect()

static void client_socket_disconnect ( void *  priv)
static

Disconnect from output IFC.

Parameters
[in,out]privpointer to private structure of input IFC (client)

Definition at line 751 of file ifc_tcpip.c.

◆ create_tcpip_receiver_ifc()

int create_tcpip_receiver_ifc ( trap_ctx_priv_t ctx,
char *  params,
trap_input_ifc_t ifc,
uint32_t  idx,
enum tcpip_ifc_sockettype  type 
)

Constructor of input TCP/IP IFC module. This function is called by TRAP library to initialize one input interface.

Parameters
[in,out]ctxPointer to the private libtrap context data (trap_ctx_init()).
[in]paramsConfiguration string containing space separated values of these parameters (in this exact order): dest_addr dest_port, where dest_addr is destination address of output TCP/IP IFC module and dest_port is the port where sender is listening.
[in,out]ifcIFC interface used for calling TCP/IP module.
[in]idxIndex of IFC that is created.
[in]typeSelect the type of socket (see tcpip_ifc_sockettype for options).
Returns
0 on success (TRAP_E_OK)

Definition at line 636 of file ifc_tcpip.c.

◆ get_cur_timestamp()

static uint64_t get_cur_timestamp ( )
inlinestatic

Return current time in microseconds.

This is used to get current timestamp in tcpip_receiver_recv() and tcpip_sender_send().

Returns
current timestamp

Definition at line 258 of file ifc_tcpip.c.

◆ receive_part()

static int receive_part ( void *  priv,
void **  data,
uint32_t *  size,
struct timeval *  tm 
)
static

Receive chunk of data.

Caller is responsible for checking elapsed time, since this function may finished before the given timeout without having data.

Parameters
[in]privprivate IFC data
[out]datareceived data
[in,out]sizeexpected size to wait for, it is used to return size that was not read
[in]tmtimeout

Definition at line 177 of file ifc_tcpip.c.

◆ tcpip_receiver_create_dump()

static void tcpip_receiver_create_dump ( void *  priv,
uint32_t  idx,
const char *  path 
)
static

Definition at line 541 of file ifc_tcpip.c.

◆ tcpip_receiver_destroy()

void tcpip_receiver_destroy ( void *  priv)

Destructor of TCPIP receiver (input ifc)

Parameters
[in]privpointer to module private data

Definition at line 520 of file ifc_tcpip.c.

◆ tcpip_receiver_recv()

int tcpip_receiver_recv ( void *  priv,
void *  data,
uint32_t *  size,
int  timeout 
)

Receive data from interface.

It is expected that data is always the same pointer because it is buffer given by trap.c.

This function contains finite state machine that controls receiving messages (header and payload), handles timeouts and sleep (to offload CPU during waiting for connection). The transition graph is:

dot_inline_dotgraph_1.png
Parameters
[in,out]privprivate configuration structure
[out]datawhere received data are stored
[out]sizesize of received data
[in]timeouttimeout in usec, can be TRAP_WAIT, TRAP_HALFWAIT, or TRAP_NO_WAIT
Returns
TRAP_E_OK (0) on success

messageframe contains header that is read (even partially) in HEAD_WAIT

Definition at line 302 of file ifc_tcpip.c.

◆ tcpip_receiver_terminate()

void tcpip_receiver_terminate ( void *  priv)

Set interface state as terminated.

Parameters
[in]privpointer to module private data

Definition at line 504 of file ifc_tcpip.c.

◆ tcpip_recv_ifc_get_id()

char* tcpip_recv_ifc_get_id ( void *  priv)

Definition at line 598 of file ifc_tcpip.c.

◆ tcpip_recv_ifc_is_conn()

uint8_t tcpip_recv_ifc_is_conn ( void *  priv)

Definition at line 611 of file ifc_tcpip.c.

◆ wait_for_connection()

static int wait_for_connection ( int  sock,
struct timeval *  tv 
)
static

Function waits for non-blocking connect().

Parameters
[in]socksocket descriptor of client
[in]tvtimeout
Returns
TRAP_E_OK on success, TRAP_E_TIMEOUT on error (can be caused by interrupt)

Definition at line 769 of file ifc_tcpip.c.