Teonet library
0.4.7
|
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "stream.h"
#include "ev_mgr.h"
#include "utils/rlutil.h"
Macros | |
#define | MODULE _ANSI_BLUE "stream" _ANSI_NONE |
File: stream.c Author: Kirill Scherba kiril l@sc herba .ruMore... | |
#define | kev ((ksnetEvMgrClass*)ks->ke) |
#define | KSN_STREAM_CONNECT_TIMEOUT 5.000 |
Functions | |
void | connect_watchers (ksnStreamClass *ks, ksnStreamMapData *data, void *key_buf, size_t key_buf_len) |
Connect watchers to pipes fd. More... | |
int | ksnStreamCloseAll (ksnStreamClass *ks) |
Close all streams. More... | |
ksnStreamClass * | ksnStreamInit (void *ke) |
Initialize Stream module. More... | |
void | ksnStreamDestroy (ksnStreamClass *ks) |
Stream module destroy. More... | |
int | ksnStreamSendTo (ksnStreamClass *ks, const char *to_peer, const char *stream_name, uint8_t cmd, void *data, size_t data_len) |
Send stream command to peer. More... | |
void | kq_connect_cb (uint32_t id, int type, void *data) |
Callback Queue callback (the same as callback queue event). More... | |
int | ksnStreamCreate (ksnStreamClass *ks, char *to_peer, char *stream_name, int send_f) |
Create new named stream with selected peer. More... | |
int | ksnStreamClose (ksnStreamClass *ks, char *to_peer, char *stream_name, int send_f) |
Close named stream with selected peer. More... | |
int | ksnStreamClosePeer (ksnStreamClass *ks, const char *peer_name) |
Close all streams connected to selected peer. More... | |
ksnStreamMapData * | ksnStreamGetMapData (ksnStreamClass *ks, void *key, size_t key_len) |
Get stream map data by key. More... | |
ksnStreamData * | ksnStreamGetDataFromMap (ksnStreamData *sd, ksnStreamMapData *smd) |
Get stream data. More... | |
void | stream_in_cb (struct ev_loop *loop, ev_io *w, int revents) |
Input stream (has data) callback. More... | |
void | stream_out_cb (struct ev_loop *loop, ev_io *w, int revents) |
Output stream (has data) callback. More... | |
int | cmd_stream_cb (ksnStreamClass *ks, ksnCorePacketData *rd) |
Process CMD_STREAM teonet command. More... | |
#define kev ((ksnetEvMgrClass*)ks->ke) |
Referenced by cmd_stream_cb(), connect_watchers(), ksnStreamClose(), ksnStreamCreate(), and ksnStreamSendTo().
#define KSN_STREAM_CONNECT_TIMEOUT 5.000 |
Referenced by ksnStreamCreate().
#define MODULE _ANSI_BLUE "stream" _ANSI_NONE |
File: stream.c Author: Kirill Scherba kiril l@sc herba .ru
Teonet stream module
Created on October 3, 2015, 3:01 PM
Referenced by cmd_stream_cb(), kq_connect_cb(), ksnStreamClose(), ksnStreamCreate(), and stream_out_cb().
int cmd_stream_cb | ( | ksnStreamClass * | ks, |
ksnCorePacketData * | rd | ||
) |
Process CMD_STREAM teonet command.
ks | |
rd |
References stream_packet::cmd, CMD_ST_CLOSE, CMD_ST_CLOSE_GOT, CMD_ST_CREATE, CMD_ST_CREATE_GOT, CMD_ST_CREATED, CMD_ST_DATA, data, stream_packet::data, ksnCorePacketData::data, stream_packet::data_len, DEBUG_VV, ksnCorePacketData::from, kev, ksn_printf, ksnStreamClose(), ksnStreamCreate(), ksnStreamClass::map, MODULE, ksnStreamMapData::pipe_in, and stream_packet::stream_name_len.
Referenced by ksnCommandCheck().
void connect_watchers | ( | ksnStreamClass * | ks, |
ksnStreamMapData * | data, | ||
void * | key_buf, | ||
size_t | key_buf_len | ||
) |
Connect watchers to pipes fd.
ks | |
data | |
key_buf | |
key_buf_len |
References ksnStreamMapData::created, data, EV_K_STREAM_CONNECTED, kev, ksnStreamMapData::pipe_in, ksnStreamMapData::pipe_out, stream_in_cb(), stream_out_cb(), ksnStreamMapData::w_in, and ksnStreamMapData::w_out.
Referenced by ksnStreamCreate().
void kq_connect_cb | ( | uint32_t | id, |
int | type, | ||
void * | data | ||
) |
Callback Queue callback (the same as callback queue event).
This function calls at timeout or after ksnCQueExec calls
id | Calls ID |
type | Type: 0 - timeout callback; 1 - successful callback |
data | Pointer to ksnStreamMapData |
References CMD_ST_CLOSE_GOT, data, DEBUG_VV, EV_K_STREAM_CONNECT_TIMEOUT, ksnetEvMgrClass::event_cb, ksnStreamMapData::ke, ke, ksnStreamMapData::key, ksnetEvMgrClass::ks, ksn_printf, ksnStreamClose(), and MODULE.
Referenced by ksnStreamCreate().
int ksnStreamClose | ( | ksnStreamClass * | ks, |
char * | to_peer, | ||
char * | stream_name, | ||
int | send_f | ||
) |
Close named stream with selected peer.
ks | |
to_peer | |
stream_name | |
send_f |
References CMD_ST_CLOSE, CMD_ST_CLOSE_GOT, CMD_ST_CLOSE_NOTREMOVE, ksnStreamMapData::created, DEBUG_VV, EV_K_STREAM_DISCONNECTED, free(), kev, ksnStreamMapData::key, ksn_printf, ksnStreamSendTo(), ksnStreamClass::map, MODULE, pblMapRemoveFree(), stream_packet::stream_name_len, ksnStreamMapData::w_in, and ksnStreamMapData::w_out.
Referenced by cmd_stream_cb(), kq_connect_cb(), ksnStreamCloseAll(), and ksnStreamClosePeer().
int ksnStreamCloseAll | ( | ksnStreamClass * | ks | ) |
Close all streams.
ks |
References CMD_ST_CLOSE_NOTREMOVE, ksnStreamClose(), and ksnStreamClass::map.
Referenced by ksnStreamDestroy().
int ksnStreamClosePeer | ( | ksnStreamClass * | ks, |
const char * | peer_name | ||
) |
Close all streams connected to selected peer.
ks | |
peer_name |
References CMD_ST_CLOSE_GOT, ksnStreamClose(), ksnStreamClosePeer(), and ksnStreamClass::map.
Referenced by ksnetArpRemove(), and ksnStreamClosePeer().
int ksnStreamCreate | ( | ksnStreamClass * | ks, |
char * | to_peer, | ||
char * | stream_name, | ||
int | send_f | ||
) |
Create new named stream with selected peer.
ks | |
to_peer | |
stream_name | |
send_f | CMD_ST_CREATE - create pipes and send CREATE request to peer; CMD_ST_CREATE_GOT - CREATE command received, create pipes and send CREATED response CMD_ST_CREATED - CREATED command received |
References CMD_ST_CREATE, CMD_ST_CREATE_GOT, CMD_ST_CREATED, connect_watchers(), ksnStreamMapData::cq, ksnStreamMapData::created, data, DEBUG_VV, ksnCQueData::id, ksnStreamMapData::ke, kev, ksnStreamMapData::key, ksnStreamMapData::key_len, kq_connect_cb(), ksn_printf, KSN_STREAM_CONNECT_TIMEOUT, ksnCQueAdd(), ksnCQueExec(), ksnStreamSendTo(), malloc(), ksnStreamClass::map, MODULE, ksnStreamMapData::pipe_in, ksnStreamMapData::pipe_out, and stream_packet::stream_name_len.
Referenced by cmd_stream_cb(), and event_cb().
void ksnStreamDestroy | ( | ksnStreamClass * | ks | ) |
Stream module destroy.
ks | Pointer to ksnStreamClass |
References free(), ksnStreamCloseAll(), and ksnStreamClass::map.
Referenced by modules_destroy().
ksnStreamData* ksnStreamGetDataFromMap | ( | ksnStreamData * | sd, |
ksnStreamMapData * | smd | ||
) |
Get stream data.
sd | Pointer to ksnStreamData |
smd | Pointer to ksnStreamMapData |
References ksnStreamData::fd_in, ksnStreamData::fd_out, ksnStreamMapData::key, ksnStreamData::peer_name, ksnStreamMapData::pipe_in, ksnStreamMapData::pipe_out, and ksnStreamData::stream_name.
Referenced by event_cb().
ksnStreamMapData* ksnStreamGetMapData | ( | ksnStreamClass * | ks, |
void * | key, | ||
size_t | key_len | ||
) |
Get stream map data by key.
ks | |
key | |
key_len |
References data, and ksnStreamClass::map.
Referenced by event_cb().
ksnStreamClass* ksnStreamInit | ( | void * | ke | ) |
Initialize Stream module.
ke | Pointer to |
References ke, ksnStreamClass::ke, malloc(), and ksnStreamClass::map.
Referenced by modules_init().
int ksnStreamSendTo | ( | ksnStreamClass * | ks, |
const char * | to_peer, | ||
const char * | stream_name, | ||
uint8_t | cmd, | ||
void * | data, | ||
size_t | data_len | ||
) |
Send stream command to peer.
ks | |
to_peer | |
stream_name | |
cmd | |
data | |
data_len |
References stream_packet::cmd, CMD_STREAM, stream_packet::data, stream_packet::data_len, free(), kev, ksnCoreSendCmdto(), malloc(), and stream_packet::stream_name_len.
Referenced by ksnStreamClose(), ksnStreamCreate(), and stream_out_cb().
void stream_in_cb | ( | struct ev_loop * | loop, |
ev_io * | w, | ||
int | revents | ||
) |
Input stream (has data) callback.
loop | |
w | |
revents |
References data, EV_K_STREAM_DATA, ksnetEvMgrClass::event_cb, ksnStreamMapData::ke, and ke.
Referenced by connect_watchers().
void stream_out_cb | ( | struct ev_loop * | loop, |
ev_io * | w, | ||
int | revents | ||
) |
Output stream (has data) callback.
loop | |
w | |
revents |
References CMD_ST_DATA, data, DEBUG_VV, ksnStreamMapData::ke, ke, ksnStreamMapData::key, ksnetEvMgrClass::ks, KSN_BUFFER_SM_SIZE, ksn_printf, ksnStreamSendTo(), MODULE, and ksnStreamMapData::pipe_out.
Referenced by connect_watchers().