Teonet library
0.4.7
|
#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 l@sc herba .ruMore... | |
#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... | |
#define kev ((ksnetEvMgrClass*)(((trudpData *)td)->user_data)) |
Referenced by ksnTRUDPsendto(), trudp_event_cb(), and trudp_process_receive().
#define MODULE _ANSI_LIGHTGREEN "tr_udp" _ANSI_NONE |
File: tr-udp.c Author: Kirill Scherba kiril l@sc herba .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().
|
inline |
Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop.
ke | Pointer to ksnetEvMgrClass |
allow | Allow if true or disallow (set by default) |
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.
td | |
fd | |
buffer | |
buffer_len | |
flags | |
addr | |
addr_len |
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.
td | Pointer to trudpData object |
resend_flg | New message or resend sent before (0 - new, 1 -resend) |
id | ID of resend message |
cmd | Command to allow TR-UDP |
attempt | Number of attempt of this message |
fd | File descriptor of UDP connection |
buf | Buffer with data |
buf_len | Data length |
flags | Flags (always 0, reserved) |
addr | Peer address |
addr_len | Peer address length |
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 | ||
) |
Receive packet from UDP or TCP Proxy buffer.
ke | Pointer to ksnetEvMgrClass |
fd | |
buffer | |
buffer_len | |
flags | |
addr | |
addr_len |
>0 | - Success |
-2 | - Buffer too small error |
-3 | - Wrong address error |
References addr_port::addr, ksnTCPProxyHeader::addr_length, addr_port_free(), ksnTCPProxyPacketData::buffer, DEBUG_VV, ksnTCPProxyClass::fd_client, ksnTCPProxyPacketData::header, kEventMgrStopped, ksn_printf, ksnetEvMgrStatus(), make_addr, MODULE, ksnTCPProxyClass::packet, ksnTCPProxyHeader::packet_length, addr_port::port, ksnTCPProxyHeader::port, teonet_cfg::r_tcp_f, ksnetEvMgrClass::teo_cfg, ksnetEvMgrClass::tp, and wrap_inet_ntop().
Referenced by trudp_process_receive().
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.
ke | Pointer to ksnetEvMgrClass |
fd | |
buffer | |
buffer_len | |
flags | |
addr | |
addr_len |
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.
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.
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 | ||
) |
Send ACK event to teonet event loop.
ke | |
id | |
data | |
data_len | |
addr |
References addr_port::addr, ksnCorePacketData::addr, addr_port_free(), ksnCorePacketData::cmd, teonet_cfg::crypt_f, EV_K_RECEIVED_ACK, ksnetEvMgrClass::event_cb, free(), ksnetEvMgrClass::kc, ksnCheckEncrypted(), ksnCoreParsePacket(), ksnDecryptPackage(), addr_port::port, ksnCorePacketData::port, rd, ksnetEvMgrClass::teo_cfg, and wrap_inet_ntop().
Referenced by trudp_event_cb().