Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tr-udp.c File Reference
#include <stdlib.h>
#include <string.h>
#include "ev_mgr.h"
#include "tr-udp.h"
#include "trudp_ev.h"

Macros

#define MODULE   _ANSI_LIGHTGREEN "tr_udp" _ANSI_NONE
 File: tr-udp.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 
#define kev   ((ksnetEvMgrClass*)(((trudpData *)td)->user_data))
 

Functions

ssize_t teo_recvfrom (ksnetEvMgrClass *ke, int fd, void *buffer, size_t buffer_len, int flags, __SOCKADDR_ARG addr, socklen_t *__restrict addr_len)
 Receive packet from UDP or TCP Proxy buffer. More...
 
ssize_t teo_sendto (ksnetEvMgrClass *ke, int fd, const void *buffer, size_t buffer_len, int flags, __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
 Send UDP packet by UDP or TCP Proxy. More...
 
int ksnetAllowAckEvent (ksnetEvMgrClass *ke, int allow)
 Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop. More...
 
ssize_t ksnTRUDPsendto (trudpData *td, int resend_flg, uint32_t id, int attempt, int cmd, int fd, const void *buf, size_t buf_len, int flags, __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
 Send to peer through TR-UDP transport. More...
 
ssize_t ksnTRUDPrecvfrom (trudpData *td, int fd, void *buffer, size_t buffer_len, int flags, __SOCKADDR_ARG addr, socklen_t *addr_len)
 Get data from peer through TR-UDP transport. More...
 
void trudp_send_event_ack_to_app (ksnetEvMgrClass *ke, uint32_t id, void *data, size_t data_length, __CONST_SOCKADDR_ARG addr)
 Send ACK event to teonet event loop. More...
 
void trudp_process_receive (trudpData *td, void *data, size_t data_length)
 Process read data from UDP. More...
 
void trudp_event_cb (void *tcd_pointer, int event, void *data, size_t data_length, void *user_data)
 TR-UDP event callback. More...
 

Macro Definition Documentation

#define kev   ((ksnetEvMgrClass*)(((trudpData *)td)->user_data))
#define MODULE   _ANSI_LIGHTGREEN "tr_udp" _ANSI_NONE

File: tr-udp.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Teonet Real time communications over UDP protocol (TR-UDP)

Created on August 4, 2015, 12:16 AM

Referenced by ksnTRUDPsendto(), and trudp_event_cb().

Function Documentation

int ksnetAllowAckEvent ( ksnetEvMgrClass ke,
int  allow 
)
inline

Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop.

Parameters
kePointer to ksnetEvMgrClass
allowAllow if true or disallow (set by default)
Returns
Previous state

References teonet_cfg::send_ack_event_f, and ksnetEvMgrClass::teo_cfg.

Referenced by main().

ssize_t ksnTRUDPrecvfrom ( trudpData *  td,
int  fd,
void *  buffer,
size_t  buffer_len,
int  flags,
__SOCKADDR_ARG  addr,
socklen_t *  addr_len 
)

Get data from peer through TR-UDP transport.

Parameters
td
fd
buffer
buffer_len
flags
addr
addr_len
Returns
If return 0 than the packet is processed by tu->process_packet function. In other case there is value returned by UDP recvfrom function and the buffer contain received data
ssize_t ksnTRUDPsendto ( trudpData *  td,
int  resend_flg,
uint32_t  id,
int  attempt,
int  cmd,
int  fd,
const void *  buf,
size_t  buf_len,
int  flags,
__CONST_SOCKADDR_ARG  addr,
socklen_t  addr_len 
)

Send to peer through TR-UDP transport.

Parameters
tdPointer to trudpData object
resend_flgNew message or resend sent before (0 - new, 1 -resend)
idID of resend message
cmdCommand to allow TR-UDP
attemptNumber of attempt of this message
fdFile descriptor of UDP connection
bufBuffer with data
buf_lenData length
flagsFlags (always 0, reserved)
addrPeer address
addr_lenPeer address length
Returns
Number of bytes sent to UDP

References addr_port::addr, addr_port_free(), CMD_TRUDP_CHECK, DEBUG_VV, DEBUG_VVV, kev, ksn_printf, MODULE, addr_port::port, and wrap_inet_ntop().

Referenced by ksnLNullPacketSend().

ssize_t teo_recvfrom ( ksnetEvMgrClass ke,
int  fd,
void *  buffer,
size_t  buffer_len,
int  flags,
__SOCKADDR_ARG  addr,
socklen_t *__restrict  addr_len 
)
ssize_t teo_sendto ( ksnetEvMgrClass ke,
int  fd,
const void *  buffer,
size_t  buffer_len,
int  flags,
__CONST_SOCKADDR_ARG  addr,
socklen_t  addr_len 
)

Send UDP packet by UDP or TCP Proxy.

Parameters
kePointer to ksnetEvMgrClass
fd
buffer
buffer_len
flags
addr
addr_len
Returns

References addr_port::addr, addr_port_free(), CMD_TCPP_PROXY, DEBUG_VV, ksnTCPProxyClass::fd_client, ksn_printf, ksnTCPProxySendTo(), MODULE, addr_port::port, teonet_cfg::r_tcp_f, ksnetEvMgrClass::teo_cfg, ksnetEvMgrClass::tp, and wrap_inet_ntop().

Referenced by trudp_event_cb().

void trudp_event_cb ( void *  tcd_pointer,
int  event,
void *  data,
size_t  data_length,
void *  user_data 
)

TR-UDP event callback.

Parameters
tcd_pointer
event
data
data_length
user_data

References _ANSI_NONE, _ANSI_RED, DEBUG_VV, kev, ksn_printf, ksn_puts, ksnCoreProcessPacket(), ksnLNullClientDisconnect(), MODULE, remove_peer_addr(), teo_sendto(), trudp_process_receive(), and trudp_send_event_ack_to_app().

Referenced by ksnCoreInit().

void trudp_process_receive ( trudpData *  td,
void *  data,
size_t  data_length 
)

Process read data from UDP.

Parameters
td
data
data_length

References kev, and teo_recvfrom().

Referenced by trudp_event_cb().

void trudp_send_event_ack_to_app ( ksnetEvMgrClass ke,
uint32_t  id,
void *  data,
size_t  data_length,
__CONST_SOCKADDR_ARG  addr 
)