Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
45 
46 #define GRN_COM_QUEUE_BINSIZE (0x100)
47 
51 };
52 
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 
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;
105 typedef void grn_msg_handler(grn_ctx *ctx, grn_obj *msg);
106 
107 enum {
113 };
114 
116  uint32_t addr;
117  uint16_t port;
118  uint16_t sid;
119 };
120 
121 struct _grn_com {
123  int events;
124  uint16_t sid;
125  uint8_t has_sid;
126  uint8_t closed;
129  void *opaque;
131 };
132 
134  struct _grn_hash *hash;
137  grn_mutex mutex;
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);
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);
169 GRN_API grn_rc grn_com_event_poll(grn_ctx *ctx, grn_com_event *ev, int timeout);
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 
180 
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);
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);
200 
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 {
212  union {
215  } u;
221 };
222 
223 GRN_API grn_rc grn_msg_send(grn_ctx *ctx, grn_obj *msg, int flags);
227  uint16_t status, uint32_t key_size, uint8_t extra_size);
229 
230 /******* grn_edge ********/
231 
232 #define GRN_EDGE_WORKER 0
233 #define GRN_EDGE_COMMUNICATOR 1
234 
235 typedef struct {
243  uint8_t stat;
244  uint8_t flags;
246 } grn_edge;
247 
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);
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 */