Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stream.h
Go to the documentation of this file.
1 
10 #ifndef STREAM_H
11 #define STREAM_H
12 
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <pbl.h>
16 #include <ev.h>
17 
18 #include "modules/cque.h"
19 
23 typedef struct ksnStreamMapData {
24 
25  int created;
26  int pipe_in[2];
27  ev_io w_in;
28  int pipe_out[2];
29  ev_io w_out;
30  void *ke;
31  void *key;
32  size_t key_len;
34 
36 
40 typedef struct ksnStreamData {
41 
42  const char *stream_name;
43  const char *peer_name;
44  int fd_in;
45  int fd_out;
46 
48 
52 enum stream_cmd {
53 
62 };
63 
67 struct stream_packet {
68 
69  uint8_t cmd;
70  uint16_t data_len;
71  uint8_t stream_name_len;
72  char data[];
73 };
74 
78 typedef struct ksnStreamClass {
79 
80  void *ke;
81  PblMap* map;
82 
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
91 int ksnStreamCreate(ksnStreamClass *ks, char *to_peer, char *stream_name,
92  int send_f);
93 int ksnStreamClose(ksnStreamClass *ks, char *to_peer, char *stream_name,
94  int send_f);
95 int ksnStreamClosePeer(ksnStreamClass *ks, const char *peer_name);
97 ksnStreamMapData *ksnStreamGetMapData(ksnStreamClass *ks, void *key, size_t key_len);
98 /*
99  * Get output stream FD
100  *
101  * @param ks Pointer to ksnStreamClass
102  * @param key Key buffer
103  * @param key_len Key buffer length
104  *
105  * @return Output stream FD
106  */
107 //#define ksnStreamGetOutFd(ks, key, key_len) ksnStreamGetMapData(ks, key, key_len)->pipe_out[1]
108 /*
109  * Get input stream FD
110  *
111  * @param ks Pointer to ksnStreamClass
112  * @param key Key buffer
113  * @param key_len Key buffer length
114  *
115  * @return Output stream FD
116  */
117 //#define ksnStreamGetInFd(ks, key, key_len) ksnStreamGetData(ks, key, key_len)->pipe_in[0]
118 //#define ksnStreamGetInFd(sd) sd->pipe_in[0]
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* STREAM_H */
char data[]
Stream data: stream_name + stream data.
Definition: stream.h:72
Create stream command.
Definition: stream.h:55
int pipe_out[2]
Output (write) pipe.
Definition: stream.h:28
int ksnStreamCreate(ksnStreamClass *ks, char *to_peer, char *stream_name, int send_f)
Create new named stream with selected peer.
Definition: stream.c:136
int fd_in
Definition: stream.h:44
int created
Created flag.
Definition: stream.h:25
Stream created (answer to create) command.
Definition: stream.h:57
File: stream.h Author: Kirill Scherba kirill@scherba.ru
Definition: stream.h:23
uint8_t cmd
Stream subcommand.
Definition: stream.h:69
Stream module class structure.
Definition: stream.h:78
const char * stream_name
Definition: stream.h:42
struct ksnStreamData ksnStreamData
Stream map data structure.
stream_cmd
Stream subcommands.
Definition: stream.h:52
struct ksnStreamMapData ksnStreamMapData
File: stream.h Author: Kirill Scherba kirill@scherba.ru
int ksnStreamClose(ksnStreamClass *ks, char *to_peer, char *stream_name, int send_f)
Close named stream with selected peer.
Definition: stream.c:244
void * ke
Pointer to ksnetEvMgrClass.
Definition: stream.h:80
ev_io w_in
Input stream watcher.
Definition: stream.h:27
ksnStreamData * ksnStreamGetDataFromMap(ksnStreamData *sd, ksnStreamMapData *smd)
Get stream data.
Definition: stream.c:375
PblMap * map
Stream map.
Definition: stream.h:81
void * key
This key (copy)
Definition: stream.h:31
Got close request from stream.
Definition: stream.h:60
uint16_t data_len
Data len.
Definition: stream.h:70
const char * peer_name
Definition: stream.h:43
Send data command.
Definition: stream.h:58
#define ke
struct ksnStreamClass ksnStreamClass
Stream module class structure.
ev_io w_out
Output stream watcher.
Definition: stream.h:29
void ksnStreamDestroy(ksnStreamClass *ks)
Stream module destroy.
Definition: stream.c:49
ksnCQue data structure
Definition: cque.h:39
void * ke
Pointer to ksnetEvMgrClass (to use in watchers)
Definition: stream.h:30
uint8_t stream_name_len
Stream name len.
Definition: stream.h:71
Definition: stream.h:54
Close stream but not remove from stream map.
Definition: stream.h:61
Close stream command.
Definition: stream.h:59
ksnCQueData * cq
Pointer to CQUEUE Data.
Definition: stream.h:33
Got create request.
Definition: stream.h:56
ksnStreamMapData * ksnStreamGetMapData(ksnStreamClass *ks, void *key, size_t key_len)
Get stream map data by key.
Definition: stream.c:355
int pipe_in[2]
Input (read) pipe.
Definition: stream.h:26
int ksnStreamClosePeer(ksnStreamClass *ks, const char *peer_name)
Close all streams connected to selected peer.
Definition: stream.c:325
ksnStreamClass * ksnStreamInit(void *ke)
Initialize Stream module.
Definition: stream.c:35
int fd_out
Definition: stream.h:45
Stream packet data structure.
Definition: stream.h:67
Stream map data structure.
Definition: stream.h:40
size_t key_len
Key length.
Definition: stream.h:32