-
Notifications
You must be signed in to change notification settings - Fork 4
/
zsock.h
129 lines (96 loc) · 3.35 KB
/
zsock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef TECHFORUM_zsock_h
# define TECHFORUM_zsock_h 1
# include <glib.h>
# include <zookeeper.h>
# include <zmq.h>
//
gint strcmp3(gconstpointer p0, gconstpointer p1, gpointer ignored);
// Transform the string form of the ZMQ type to the ZMQ_* constant
GError* zsocket_resolve(const gchar *zname, int *ztype);
//------------------------------------------------------------------------------
struct cfg_listen_s
{
gchar *type;
gchar *ztype;
gchar *uuid;
gchar *cell;
gchar *url;
};
struct cfg_sock_s
{
gchar *sockname;
gchar *ztype;
gchar **connect; // pairs of char*
gchar **listen; // char*
};
struct cfg_srv_s
{
gchar *srvtype;
GPtrArray *socks; // (struct cfg_sock_s *)
};
void cfg_listen_destroy(struct cfg_listen_s *cfg);
void cfg_sock_destroy(struct cfg_sock_s *cfg);
void cfg_srv_destroy(struct cfg_srv_s *cfg);
struct cfg_listen_s * zlisten_parse_config_buffer(const gchar *b, gsize blen);
struct cfg_srv_s * zservice_parse_config_buffer(const gchar *b, gsize bl);
struct cfg_srv_s * zservice_parse_config_string(const gchar *cfg);
struct cfg_srv_s* zservice_parse_config_from_path(const gchar *path);
//------------------------------------------------------------------------------
struct zconnect_s
{
gchar *type;
gchar *policy;
gchar **urlv_current;
GPtrArray *urlv_new; // (struct cfg_listen_s*)
guint list_wanted;
guint list_pending;
guint get_pending;
struct zsock_s *zs; // the socket it belongs to
};
struct zsock_s
{
void *zctx; // a ZMQ context
void *zs; // ZMQ socket
zhandle_t *zh; // ZooKeeper handle
gchar *fullname;
gchar *localname;
const gchar *puuid;
const gchar *pcell;
gboolean paused_input;
GTree *connect_real; // char* -> gulong
GTree *connect_cfg; // char* -> (struct zconnect_s*)
GTree *bind_set; // char* -> char*
void (*ready_out)(struct zsock_s*);
void (*ready_in)(struct zsock_s*);
int evt; // to be monitored ZMQ_POLLIN|ZMQ_POLLOUT
};
struct zservice_s
{
void *zctx; // a ZMQ context
struct zreactor_s *zr; // the reactor managing this reactor
zhandle_t *zh; // the ZooKeeper handle
gpointer on_config_data;
void (*on_config)(struct zservice_s *zsrv, gpointer data);
gchar *srvtype;
GTree *socks;
gchar uuid[32];
gchar cell[32];
};
//------------------------------------------------------------------------------
/* Create the structure and _SOME_ of its internal field. */
struct zsock_s* zsock_create(const gchar *uuid, const gchar *cell);
void zsock_destroy(struct zsock_s *zsock);
gboolean zsock_ready(struct zsock_s *zsock);
void zsock_configure(struct zsock_s *zsock, struct cfg_sock_s *cfg);
void zsock_register_in_reactor(struct zreactor_s *zr, struct zsock_s *zsock);
void zsock_connect(struct zsock_s *zsock, const gchar *type,
const gchar *policy);
//------------------------------------------------------------------------------
struct zservice_s* zservice_create(void *zctx, zhandle_t *zh, const gchar *srvtype);
void zservice_destroy(struct zservice_s *zsrv);
struct zsock_s* zservice_get_socket(struct zservice_s *zsrv, const gchar *n);
void zservice_register_in_reactor(struct zreactor_s *zr,
struct zservice_s *zsrv);
void zservice_on_config(struct zservice_s *zsrv, gpointer u,
void (*hook)(struct zservice_s*, gpointer));
#endif // TECHFORUM_zsock_h