Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stream.c File Reference
#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.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 
#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...
 
ksnStreamClassksnStreamInit (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...
 
ksnStreamMapDataksnStreamGetMapData (ksnStreamClass *ks, void *key, size_t key_len)
 Get stream map data by key. More...
 
ksnStreamDataksnStreamGetDataFromMap (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...
 

Macro Definition Documentation

#define KSN_STREAM_CONNECT_TIMEOUT   5.000

Referenced by ksnStreamCreate().

#define MODULE   _ANSI_BLUE "stream" _ANSI_NONE

File: stream.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..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().

Function Documentation

void connect_watchers ( ksnStreamClass ks,
ksnStreamMapData data,
void *  key_buf,
size_t  key_buf_len 
)
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

Parameters
idCalls ID
typeType: 0 - timeout callback; 1 - successful callback
dataPointer 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 
)
int ksnStreamCloseAll ( ksnStreamClass ks)

Close all streams.

Parameters
ks
Returns

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.

Parameters
ks
peer_name
Returns

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.

Parameters
ks
to_peer
stream_name
send_fCMD_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
Returns
Examples:
teostream.c.

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.

Parameters
ksPointer to ksnStreamClass

References free(), ksnStreamCloseAll(), and ksnStreamClass::map.

Referenced by modules_destroy().

ksnStreamData* ksnStreamGetDataFromMap ( ksnStreamData sd,
ksnStreamMapData smd 
)
ksnStreamMapData* ksnStreamGetMapData ( ksnStreamClass ks,
void *  key,
size_t  key_len 
)

Get stream map data by key.

Parameters
ks
key
key_len
Returns
Pointer to ksnStreamMapData or NULL if not found
Examples:
teostream.c.

References data, and ksnStreamClass::map.

Referenced by event_cb().

ksnStreamClass* ksnStreamInit ( void *  ke)

Initialize Stream module.

Parameters
kePointer to
Returns

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.

Parameters
ks
to_peer
stream_name
cmd
data
data_len
Returns

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.

Parameters
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 
)