Groonga 3.0.9 Source Code Document
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
groonga
lib
com.h
Go to the documentation of this file.
1
/* -*- c-basic-offset: 2 -*- */
2
/* Copyright(C) 2009-2012 Brazil
3
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License version 2.1 as published by the Free Software Foundation.
7
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Lesser General Public License for more details.
12
13
You should have received a copy of the GNU Lesser General Public
14
License along with this library; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
*/
17
18
#ifndef GRN_COM_H
19
#define GRN_COM_H
20
21
#ifndef GROONGA_H
22
#include "
groonga_in.h
"
23
#endif
/* GROONGA_H */
24
25
#ifndef GRN_STR_H
26
#include "
str.h
"
27
#endif
/* GRN_STR_H */
28
29
#ifndef GRN_HASH_H
30
#include "
hash.h
"
31
#endif
/* GRN_HASH_H */
32
33
#ifdef HAVE_NETDB_H
34
#include <netdb.h>
35
#endif
/* HAVE_NETDB_H */
36
37
#ifdef __cplusplus
38
extern
"C"
{
39
#endif
40
41
/******* grn_com_queue ********/
42
43
typedef
struct
_grn_com_queue
grn_com_queue
;
44
typedef
struct
_grn_com_queue_entry
grn_com_queue_entry
;
45
46
#define GRN_COM_QUEUE_BINSIZE (0x100)
47
48
struct
_grn_com_queue_entry
{
49
grn_obj
obj
;
50
struct
_grn_com_queue_entry
*
next
;
51
};
52
53
struct
_grn_com_queue
{
54
grn_com_queue_entry
*
bins
[
GRN_COM_QUEUE_BINSIZE
];
55
grn_com_queue_entry
*
next
;
56
grn_com_queue_entry
**
tail
;
57
uint8_t
first
;
58
uint8_t
last
;
59
grn_critical_section
cs
;
60
};
61
62
#define GRN_COM_QUEUE_INIT(q) do {\
63
(q)->next = NULL;\
64
(q)->tail = &(q)->next;\
65
(q)->first = 0;\
66
(q)->last = 0;\
67
CRITICAL_SECTION_INIT((q)->cs);\
68
} while (0)
69
70
#define GRN_COM_QUEUE_EMPTYP(q) (((q)->first == (q)->last) && !(q)->next)
71
72
GRN_API
grn_rc
grn_com_queue_enque
(
grn_ctx
*ctx,
grn_com_queue
*q,
grn_com_queue_entry
*e);
73
GRN_API
grn_com_queue_entry
*
grn_com_queue_deque
(
grn_ctx
*ctx,
grn_com_queue
*q);
74
75
/******* grn_com ********/
76
77
#ifdef USE_SELECT
78
# ifdef HAVE_SYS_SELECT_H
79
# include <sys/select.h>
80
# endif
/* HAVE_SYS_SELECT_H */
81
# define GRN_COM_POLLIN 1
82
# define GRN_COM_POLLOUT 2
83
#else
/* USE_SELECT */
84
# ifdef USE_EPOLL
85
# include <sys/epoll.h>
86
# define GRN_COM_POLLIN EPOLLIN
87
# define GRN_COM_POLLOUT EPOLLOUT
88
# else
/* USE_EPOLL */
89
# ifdef USE_KQUEUE
90
# include <sys/event.h>
91
# define GRN_COM_POLLIN EVFILT_READ
92
# define GRN_COM_POLLOUT EVFILT_WRITE
93
# else
/* USE_KQUEUE */
94
# include <sys/poll.h>
95
# define GRN_COM_POLLIN POLLIN
96
# define GRN_COM_POLLOUT POLLOUT
97
# endif
/* USE_KQUEUE */
98
# endif
/* USE_EPOLL */
99
#endif
/* USE_SELECT */
100
101
typedef
struct
_grn_com
grn_com
;
102
typedef
struct
_grn_com_event
grn_com_event
;
103
typedef
struct
_grn_com_addr
grn_com_addr
;
104
typedef
void
grn_com_callback
(
grn_ctx
*ctx,
grn_com_event
*,
grn_com
*);
105
typedef
void
grn_msg_handler
(
grn_ctx
*ctx,
grn_obj
*msg);
106
107
enum
{
108
grn_com_ok
= 0,
109
grn_com_emem
,
110
grn_com_erecv_head
,
111
grn_com_erecv_body
,
112
grn_com_eproto
,
113
};
114
115
struct
_grn_com_addr
{
116
uint32_t
addr
;
117
uint16_t
port
;
118
uint16_t
sid
;
119
};
120
121
struct
_grn_com
{
122
grn_sock
fd
;
123
int
events
;
124
uint16_t
sid
;
125
uint8_t
has_sid
;
126
uint8_t
closed
;
127
grn_com_queue
new_
;
128
grn_com_event
*
ev
;
129
void
*
opaque
;
130
grn_bool
accepting
;
131
};
132
133
struct
_grn_com_event
{
134
struct
_grn_hash
*
hash
;
135
int
max_nevents
;
136
grn_ctx
*
ctx
;
137
grn_mutex
mutex
;
138
grn_cond
cond
;
139
grn_com_queue
recv_old
;
140
grn_msg_handler
*
msg_handler
;
141
grn_com_addr
curr_edge_id
;
142
grn_com
*
acceptor
;
143
void
*
opaque
;
144
#ifndef USE_SELECT
145
#ifdef USE_EPOLL
146
int
epfd;
147
struct
epoll_event *
events
;
148
#else
/* USE_EPOLL */
149
#ifdef USE_KQUEUE
150
int
kqfd;
151
struct
kevent *
events
;
152
#else
/* USE_KQUEUE */
153
int
dummy
;
/* dummy */
154
struct
pollfd *
events
;
155
#endif
/* USE_KQUEUE */
156
#endif
/* USE_EPOLL */
157
#endif
/* USE_SELECT */
158
};
159
160
grn_rc
grn_com_init
(
void
);
161
void
grn_com_fin
(
void
);
162
GRN_API
grn_rc
grn_com_event_init
(
grn_ctx
*ctx,
grn_com_event
*ev,
int
max_nevents,
int
data_size);
163
GRN_API
grn_rc
grn_com_event_fin
(
grn_ctx
*ctx,
grn_com_event
*ev);
164
GRN_API
grn_rc
grn_com_event_start_accept
(
grn_ctx
*ctx,
grn_com_event
*ev);
165
grn_rc
grn_com_event_stop_accept
(
grn_ctx
*ctx,
grn_com_event
*ev);
166
grn_rc
grn_com_event_add
(
grn_ctx
*ctx,
grn_com_event
*ev,
grn_sock
fd,
int
events,
grn_com
**com);
167
grn_rc
grn_com_event_mod
(
grn_ctx
*ctx,
grn_com_event
*ev,
grn_sock
fd,
int
events,
grn_com
**com);
168
GRN_API
grn_rc
grn_com_event_del
(
grn_ctx
*ctx,
grn_com_event
*ev,
grn_sock
fd);
169
GRN_API
grn_rc
grn_com_event_poll
(
grn_ctx
*ctx,
grn_com_event
*ev,
int
timeout);
170
grn_rc
grn_com_event_each
(
grn_ctx
*ctx,
grn_com_event
*ev,
grn_com_callback
*func);
171
172
/******* grn_com_gqtp ********/
173
174
#define GRN_COM_PROTO_HTTP 0x47
175
#define GRN_COM_PROTO_GQTP 0xc7
176
#define GRN_COM_PROTO_MBREQ 0x80
177
#define GRN_COM_PROTO_MBRES 0x81
178
179
typedef
struct
_grn_com_header
grn_com_header
;
180
181
struct
_grn_com_header
{
182
uint8_t
proto
;
183
uint8_t
qtype
;
184
uint16_t
keylen
;
185
uint8_t
level
;
186
uint8_t
flags
;
187
uint16_t
status
;
188
uint32_t
size
;
189
uint32_t
opaque
;
190
uint64_t
cas
;
191
};
192
193
GRN_API
grn_com
*
grn_com_copen
(
grn_ctx
*ctx,
grn_com_event
*ev,
const
char
*dest,
int
port);
194
GRN_API
grn_rc
grn_com_sopen
(
grn_ctx
*ctx,
grn_com_event
*ev,
195
const
char
*bind_address,
int
port,
196
grn_msg_handler
*func,
struct
hostent *he);
197
198
GRN_API
void
grn_com_close_
(
grn_ctx
*ctx,
grn_com
*com);
199
GRN_API
grn_rc
grn_com_close
(
grn_ctx
*ctx,
grn_com
*com);
200
201
GRN_API
grn_rc
grn_com_send
(
grn_ctx
*ctx,
grn_com
*cs,
202
grn_com_header
*header,
const
char
*body, uint32_t size,
int
flags);
203
grn_rc
grn_com_recv
(
grn_ctx
*ctx,
grn_com
*cs,
grn_com_header
*header,
grn_obj
*buf);
204
GRN_API
grn_rc
grn_com_send_http
(
grn_ctx
*ctx,
grn_com
*cs,
const
char
*path, uint32_t path_len,
int
flags);
205
206
/******* grn_msg ********/
207
208
typedef
struct
_grn_msg
grn_msg
;
209
210
struct
_grn_msg
{
211
grn_com_queue_entry
qe
;
212
union
{
213
grn_com
*
peer
;
214
grn_sock
fd
;
215
}
u
;
216
grn_ctx
*
ctx
;
217
grn_com_queue
*
old
;
218
grn_com_header
header
;
219
grn_com_addr
edge_id
;
220
grn_com
*
acceptor
;
221
};
222
223
GRN_API
grn_rc
grn_msg_send
(
grn_ctx
*ctx,
grn_obj
*msg,
int
flags);
224
GRN_API
grn_obj
*
grn_msg_open_for_reply
(
grn_ctx
*ctx,
grn_obj
*query,
grn_com_queue
*old);
225
GRN_API
grn_obj
*
grn_msg_open
(
grn_ctx
*ctx,
grn_com
*com,
grn_com_queue
*old);
226
GRN_API
grn_rc
grn_msg_set_property
(
grn_ctx
*ctx,
grn_obj
*obj,
227
uint16_t status, uint32_t key_size, uint8_t extra_size);
228
GRN_API
grn_rc
grn_msg_close
(
grn_ctx
*ctx,
grn_obj
*msg);
229
230
/******* grn_edge ********/
231
232
#define GRN_EDGE_WORKER 0
233
#define GRN_EDGE_COMMUNICATOR 1
234
235
typedef
struct
{
236
grn_com_queue_entry
eq
;
237
grn_ctx
ctx
;
238
grn_com_queue
recv_new
;
239
grn_com_queue
send_old
;
240
grn_com
*
com
;
241
grn_com_addr
*
addr
;
242
grn_msg
*
msg
;
243
uint8_t
stat
;
244
uint8_t
flags
;
245
grn_id
id
;
246
}
grn_edge
;
247
248
GRN_VAR
grn_hash
*
grn_edges
;
249
GRN_API
void
grn_edges_init
(
grn_ctx
*ctx,
void
(*dispatcher)(
grn_ctx
*ctx,
grn_edge
*edge));
250
GRN_API
void
grn_edges_fin
(
grn_ctx
*ctx);
251
GRN_API
grn_edge
*
grn_edges_add
(
grn_ctx
*ctx,
grn_com_addr
*addr,
int
*added);
252
grn_edge
*
grn_edges_add_communicator
(
grn_ctx
*ctx,
grn_com_addr
*addr);
253
GRN_API
void
grn_edges_delete
(
grn_ctx
*ctx,
grn_edge
*edge);
254
void
grn_edge_dispatch
(
grn_ctx
*ctx,
grn_edge
*edge,
grn_obj
*msg);
255
256
#ifdef __cplusplus
257
}
258
#endif
259
260
#endif
/* GRN_COM_H */
Generated on Sun Nov 10 2013 09:49:01 for Groonga 3.0.9 Source Code Document by
1.8.1.2