lwtarantool 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +84 -0
- data/ext/lwtarantool/conn.c +314 -0
- data/ext/lwtarantool/depend +23 -0
- data/ext/lwtarantool/errors.c +24 -0
- data/ext/lwtarantool/extconf.rb +8 -0
- data/ext/lwtarantool/lwtarantool.c +12 -0
- data/ext/lwtarantool/lwtarantool.h +38 -0
- data/ext/lwtarantool/request.c +124 -0
- data/ext/lwtarantool/vendor/msgpuck/CMakeLists.txt +73 -0
- data/ext/lwtarantool/vendor/msgpuck/hints.c +674 -0
- data/ext/lwtarantool/vendor/msgpuck/msgpuck.c +375 -0
- data/ext/lwtarantool/vendor/msgpuck/msgpuck.h +2195 -0
- data/ext/lwtarantool/vendor/msgpuck/test/CMakeLists.txt +25 -0
- data/ext/lwtarantool/vendor/msgpuck/test/msgpuck.c +1126 -0
- data/ext/lwtarantool/vendor/msgpuck/test/test.c +105 -0
- data/ext/lwtarantool/vendor/msgpuck/test/test.h +123 -0
- data/ext/lwtarantool/vendor/tarantool-c/CMakeLists.txt +89 -0
- data/ext/lwtarantool/vendor/tarantool-c/cmake/FindMsgPuck.cmake +18 -0
- data/ext/lwtarantool/vendor/tarantool-c/cmake/FindSphinx.cmake +10 -0
- data/ext/lwtarantool/vendor/tarantool-c/doc/CMakeLists.txt +15 -0
- data/ext/lwtarantool/vendor/tarantool-c/doc/source/example.c +340 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/CMakeLists.txt +6 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tarantool.h +67 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_auth.h +72 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_buf.h +88 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_call.h +83 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_delete.h +52 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_execute.h +24 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_insert.h +62 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_io.h +67 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_iob.h +62 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_iter.h +301 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_mem.h +102 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_net.h +242 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_object.h +248 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_opt.h +138 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_ping.h +49 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_proto.h +295 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_reply.h +204 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_request.h +377 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_schema.h +165 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_select.h +59 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_stream.h +79 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tarantool/tnt_update.h +226 -0
- data/ext/lwtarantool/vendor/tarantool-c/include/tp.h +1998 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/CMakeLists.txt +36 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/common.c +233 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/common.h +28 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/plain_test.c +152 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/tarantool_call.c +57 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/tarantool_disconnect.c +31 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/tarantool_tcp.c +840 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/tarantool_unix.c +384 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/test.c +72 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/test.h +94 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/tnt_assoc.c +6 -0
- data/ext/lwtarantool/vendor/tarantool-c/test/tnt_assoc.h +67 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/PMurHash.c +317 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/PMurHash.h +68 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/base64.c +300 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/base64.h +91 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/mhash.h +589 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/sha1.c +219 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/sha1.h +24 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/uri.c +6528 -0
- data/ext/lwtarantool/vendor/tarantool-c/third_party/uri.h +81 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/CMakeLists.txt +83 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/pmatomic.h +494 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_assoc.c +9 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_assoc.h +172 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_auth.c +118 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_buf.c +171 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_call.c +79 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_delete.c +52 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_execute.c +60 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_insert.c +60 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_io.c +520 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_iob.c +75 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_iter.c +293 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_mem.c +82 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_net.c +336 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_object.c +476 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_opt.c +117 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_ping.c +38 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_proto_internal.h +43 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_reply.c +300 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_request.c +336 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_schema.c +334 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_select.c +58 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_stream.c +71 -0
- data/ext/lwtarantool/vendor/tarantool-c/tnt/tnt_update.c +247 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/CMakeLists.txt +69 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_dir.c +173 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_dir.h +58 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_log.c +329 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_log.h +119 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_rpl.c +189 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_rpl.h +47 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_snapshot.c +163 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_snapshot.h +50 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_xlog.c +163 -0
- data/ext/lwtarantool/vendor/tarantool-c/tntrpl/tnt_xlog.h +50 -0
- data/lib/lwtarantool/connection.rb +84 -0
- data/lib/lwtarantool/request.rb +58 -0
- data/lib/lwtarantool.rb +23 -0
- metadata +164 -0
@@ -0,0 +1,301 @@
|
|
1
|
+
#ifndef TNT_ITER_H_INCLUDED
|
2
|
+
#define TNT_ITER_H_INCLUDED
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Redistribution and use in source and binary forms, with or
|
6
|
+
* without modification, are permitted provided that the following
|
7
|
+
* conditions are met:
|
8
|
+
*
|
9
|
+
* 1. Redistributions of source code must retain the above
|
10
|
+
* copyright notice, this list of conditions and the
|
11
|
+
* following disclaimer.
|
12
|
+
*
|
13
|
+
* 2. Redistributions in binary form must reproduce the above
|
14
|
+
* copyright notice, this list of conditions and the following
|
15
|
+
* disclaimer in the documentation and/or other materials
|
16
|
+
* provided with the distribution.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
|
19
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
20
|
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
22
|
+
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
26
|
+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
29
|
+
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
30
|
+
* SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
/**
|
34
|
+
* \file tnt_iter.h
|
35
|
+
* \brief Custom iterator types (msgpack/reply)
|
36
|
+
*/
|
37
|
+
|
38
|
+
/*!
|
39
|
+
* iterator types
|
40
|
+
*/
|
41
|
+
enum tnt_iter_type {
|
42
|
+
TNT_ITER_ARRAY,
|
43
|
+
TNT_ITER_MAP,
|
44
|
+
TNT_ITER_REPLY,
|
45
|
+
// TNT_ITER_REQUEST,
|
46
|
+
// TNT_ITER_STORAGE
|
47
|
+
};
|
48
|
+
|
49
|
+
/*!
|
50
|
+
* \brief msgpack array iterator
|
51
|
+
*/
|
52
|
+
struct tnt_iter_array {
|
53
|
+
const char *data; /*!< pointer to the beginning of array */
|
54
|
+
const char *first_elem; /*!< pointer to the first element of array */
|
55
|
+
const char *elem; /*!< pointer to current element of array */
|
56
|
+
const char *elem_end; /*!< pointer to current element end of array */
|
57
|
+
uint32_t elem_count; /*!< number of elements in array */
|
58
|
+
int cur_index; /*!< index of current element */
|
59
|
+
};
|
60
|
+
|
61
|
+
/* msgpack array iterator accessors */
|
62
|
+
|
63
|
+
/**
|
64
|
+
* \brief access msgpack array iterator
|
65
|
+
*/
|
66
|
+
#define TNT_IARRAY(I) (&(I)->data.array)
|
67
|
+
|
68
|
+
/**
|
69
|
+
* \brief access current element form iterator
|
70
|
+
*/
|
71
|
+
#define TNT_IARRAY_ELEM(I) TNT_IARRAY(I)->elem
|
72
|
+
|
73
|
+
/**
|
74
|
+
* \brief access end of current element from iterator
|
75
|
+
*/
|
76
|
+
#define TNT_IARRAY_ELEM_END(I) TNT_IARRAY(I)->elem_end
|
77
|
+
|
78
|
+
/*!
|
79
|
+
* \brief msgpack map iterator
|
80
|
+
*/
|
81
|
+
struct tnt_iter_map {
|
82
|
+
const char *data; /*!< pointer to the beginning of map */
|
83
|
+
const char *first_key; /*!< pointer to the first key of map */
|
84
|
+
const char *key; /*!< pointer to current key of map */
|
85
|
+
const char *key_end; /*!< pointer to current key end */
|
86
|
+
const char *value; /*!< pointer to current value of map */
|
87
|
+
const char *value_end; /*!< pointer to current value end */
|
88
|
+
uint32_t pair_count; /*!< number of key-values pairs in array */
|
89
|
+
int cur_index; /*!< index of current pair */
|
90
|
+
};
|
91
|
+
|
92
|
+
/* msgpack array iterator accessors */
|
93
|
+
|
94
|
+
/**
|
95
|
+
* \brief access msgpack map iterator
|
96
|
+
*/
|
97
|
+
#define TNT_IMAP(I) (&(I)->data.map)
|
98
|
+
|
99
|
+
/**
|
100
|
+
* \brief access current key from iterator
|
101
|
+
*/
|
102
|
+
#define TNT_IMAP_KEY(I) TNT_IMAP(I)->key
|
103
|
+
|
104
|
+
/**
|
105
|
+
* \brief access current key end from iterator
|
106
|
+
*/
|
107
|
+
#define TNT_IMAP_KEY_END(I) TNT_IMAP(I)->key_end
|
108
|
+
|
109
|
+
/**
|
110
|
+
* \brief access current value from iterator
|
111
|
+
*/
|
112
|
+
#define TNT_IMAP_VAL(I) TNT_IMAP(I)->value
|
113
|
+
|
114
|
+
/**
|
115
|
+
* \brief access current value end from iterator
|
116
|
+
*/
|
117
|
+
#define TNT_IMAP_VAL_END(I) TNT_IMAP(I)->value_end
|
118
|
+
|
119
|
+
/*!
|
120
|
+
* \brief reply iterator
|
121
|
+
*/
|
122
|
+
struct tnt_iter_reply {
|
123
|
+
struct tnt_stream *s; /*!< stream pointer */
|
124
|
+
struct tnt_reply r; /*!< current reply */
|
125
|
+
};
|
126
|
+
|
127
|
+
/* reply iterator accessors */
|
128
|
+
|
129
|
+
/**
|
130
|
+
* \brief access reply iterator
|
131
|
+
*/
|
132
|
+
#define TNT_IREPLY(I) (&(I)->data.reply)
|
133
|
+
|
134
|
+
/**
|
135
|
+
* \brief access current reply form iterator
|
136
|
+
*/
|
137
|
+
#define TNT_IREPLY_PTR(I) &TNT_IREPLY(I)->r
|
138
|
+
|
139
|
+
/* request iterator */
|
140
|
+
// struct tnt_iter_request {
|
141
|
+
// struct tnt_stream *s; /* stream pointer */
|
142
|
+
// struct tnt_request r; /* current request */
|
143
|
+
// };
|
144
|
+
|
145
|
+
/* request iterator accessors */
|
146
|
+
// #define TNT_IREQUEST(I) (&(I)->data.request)
|
147
|
+
// #define TNT_IREQUEST_PTR(I) &TNT_IREQUEST(I)->r
|
148
|
+
// #define TNT_IREQUEST_STREAM(I) TNT_IREQUEST(I)->s
|
149
|
+
|
150
|
+
/* storage iterator */
|
151
|
+
// struct tnt_iter_storage {
|
152
|
+
// struct tnt_stream *s; /* stream pointer */
|
153
|
+
// struct tnt_tuple t; /* current fetched tuple */
|
154
|
+
// };
|
155
|
+
|
156
|
+
/* storage iterator accessors */
|
157
|
+
// #define TNT_ISTORAGE(I) (&(I)->data.storage)
|
158
|
+
// #define TNT_ISTORAGE_TUPLE(I) &TNT_ISTORAGE(I)->t
|
159
|
+
// #define TNT_ISTORAGE_STREAM(I) TNT_ISTORAGE(I)->s
|
160
|
+
|
161
|
+
/**
|
162
|
+
* \brief iterator status
|
163
|
+
*/
|
164
|
+
enum tnt_iter_status {
|
165
|
+
TNT_ITER_OK, /*!< iterator is ok */
|
166
|
+
TNT_ITER_FAIL /*!< error or end of iteration */
|
167
|
+
};
|
168
|
+
|
169
|
+
/**
|
170
|
+
* \brief Common iterator object
|
171
|
+
*/
|
172
|
+
struct tnt_iter {
|
173
|
+
enum tnt_iter_type type; /*!< iterator type
|
174
|
+
* \sa enum tnt_iter_type
|
175
|
+
*/
|
176
|
+
enum tnt_iter_status status; /*!< iterator status
|
177
|
+
* \sa enum tnt_iter_status
|
178
|
+
*/
|
179
|
+
int alloc; /*!< allocation mark */
|
180
|
+
/* interface callbacks */
|
181
|
+
int (*next)(struct tnt_iter *iter); /*!< callback for next element */
|
182
|
+
void (*rewind)(struct tnt_iter *iter); /*!< callback for rewind */
|
183
|
+
void (*free)(struct tnt_iter *iter); /*!< callback for free of custom iter type */
|
184
|
+
/* iterator data */
|
185
|
+
union {
|
186
|
+
struct tnt_iter_array array; /*!< msgpack array iterator */
|
187
|
+
struct tnt_iter_map map; /*!< msgpack map iterator */
|
188
|
+
struct tnt_iter_reply reply; /*!< reply iterator */
|
189
|
+
// struct tnt_iter_request request;
|
190
|
+
// struct tnt_iter_storage storage;
|
191
|
+
} data;
|
192
|
+
};
|
193
|
+
|
194
|
+
/**
|
195
|
+
* \brief create msgpack array iterator from object
|
196
|
+
*
|
197
|
+
* if iterator pointer is NULL, then new iterator will be created.
|
198
|
+
*
|
199
|
+
* \param i pointer to allocated structure
|
200
|
+
* \param s tnt_object/tnt_buf instance with array to traverse
|
201
|
+
*
|
202
|
+
* \returns iterator pointer
|
203
|
+
* \retval NULL on error.
|
204
|
+
*/
|
205
|
+
struct tnt_iter *
|
206
|
+
tnt_iter_array_object(struct tnt_iter *i, struct tnt_stream *s);
|
207
|
+
|
208
|
+
/**
|
209
|
+
* \brief create msgpack array iterator from pointer
|
210
|
+
*
|
211
|
+
* if iterator pointer is NULL, then new iterator will be created.
|
212
|
+
*
|
213
|
+
* \param i pointer to allocated structure
|
214
|
+
* \param data pointer to data with array
|
215
|
+
* \param size size of data (may be more, it won't go outside)
|
216
|
+
*
|
217
|
+
* \returns iterator pointer
|
218
|
+
* \retval NULL on error.
|
219
|
+
*/
|
220
|
+
struct tnt_iter *
|
221
|
+
tnt_iter_array(struct tnt_iter *i, const char *data, size_t size);
|
222
|
+
|
223
|
+
/**
|
224
|
+
* \brief create msgpack map iterator from object
|
225
|
+
*
|
226
|
+
* if iterator pointer is NULL, then new iterator will be created.
|
227
|
+
*
|
228
|
+
* \param i pointer to allocated structure
|
229
|
+
* \param s tnt_object/tnt_buf instance with map to traverse
|
230
|
+
*
|
231
|
+
* \returns iterator pointer
|
232
|
+
* \retval NULL error.
|
233
|
+
*/
|
234
|
+
struct tnt_iter *
|
235
|
+
tnt_iter_map_object(struct tnt_iter *i, struct tnt_stream *s);
|
236
|
+
|
237
|
+
/**
|
238
|
+
* \brief create msgpack map iterator from pointer
|
239
|
+
*
|
240
|
+
* if iterator pointer is NULL, then new iterator will be created.
|
241
|
+
*
|
242
|
+
* \param i pointer to allocated structure
|
243
|
+
* \param data pointer to data with map
|
244
|
+
* \param size size of data (may be more, it won't go outside)
|
245
|
+
*
|
246
|
+
* \returns iterator pointer
|
247
|
+
* \retval NULL error.
|
248
|
+
*/
|
249
|
+
struct tnt_iter *
|
250
|
+
tnt_iter_map(struct tnt_iter *i, const char *data, size_t size);
|
251
|
+
|
252
|
+
/**
|
253
|
+
* \brief create and initialize tuple reply iterator;
|
254
|
+
*
|
255
|
+
* \param i pointer to allocated structure
|
256
|
+
* \param s tnt_net stream pointer
|
257
|
+
*
|
258
|
+
* if stream iterator pointer is NULL, then new stream
|
259
|
+
* iterator will be created.
|
260
|
+
*
|
261
|
+
* \returns stream iterator pointer
|
262
|
+
* \retval NULL error.
|
263
|
+
*/
|
264
|
+
struct tnt_iter *
|
265
|
+
tnt_iter_reply(struct tnt_iter *i, struct tnt_stream *s);
|
266
|
+
|
267
|
+
// struct tnt_iter *tnt_iter_request(struct tnt_iter *i, struct tnt_stream *s);
|
268
|
+
// struct tnt_iter *tnt_iter_storag(struct tnt_iter *i, struct tnt_stream *s);
|
269
|
+
|
270
|
+
/**
|
271
|
+
* \brief free iterator.
|
272
|
+
*
|
273
|
+
* \param i iterator pointer
|
274
|
+
*/
|
275
|
+
void
|
276
|
+
tnt_iter_free(struct tnt_iter *i);
|
277
|
+
|
278
|
+
/**
|
279
|
+
* \brief iterate to next element in tuple
|
280
|
+
*
|
281
|
+
* \param i iterator pointer
|
282
|
+
*
|
283
|
+
* depend on iterator tuple, sets to the
|
284
|
+
* next msgpack field or next response in the stream.
|
285
|
+
*
|
286
|
+
* \retval 0 end of iteration
|
287
|
+
* \retval 1 next step of iteration
|
288
|
+
*/
|
289
|
+
int
|
290
|
+
tnt_next(struct tnt_iter *i);
|
291
|
+
|
292
|
+
/**
|
293
|
+
* \brief reset iterator pos to beginning
|
294
|
+
*
|
295
|
+
* \param i iterator pointer
|
296
|
+
*/
|
297
|
+
void
|
298
|
+
tnt_rewind(struct tnt_iter *i);
|
299
|
+
|
300
|
+
|
301
|
+
#endif /* TNT_ITER_H_INCLUDED */
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#ifndef TNT_MEM_H_INCLUDED
|
2
|
+
#define TNT_MEM_H_INCLUDED
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Redistribution and use in source and binary forms, with or
|
6
|
+
* without modification, are permitted provided that the following
|
7
|
+
* conditions are met:
|
8
|
+
*
|
9
|
+
* 1. Redistributions of source code must retain the above
|
10
|
+
* copyright notice, this list of conditions and the
|
11
|
+
* following disclaimer.
|
12
|
+
*
|
13
|
+
* 2. Redistributions in binary form must reproduce the above
|
14
|
+
* copyright notice, this list of conditions and the following
|
15
|
+
* disclaimer in the documentation and/or other materials
|
16
|
+
* provided with the distribution.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
|
19
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
20
|
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
22
|
+
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
26
|
+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
29
|
+
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
30
|
+
* SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
/**
|
34
|
+
* \internal
|
35
|
+
* \file tnt_mem.h
|
36
|
+
* \brief Basic memory functions
|
37
|
+
*/
|
38
|
+
|
39
|
+
#define tntfunction_unused __attribute__((unused))
|
40
|
+
|
41
|
+
#if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || \
|
42
|
+
defined __SUNPRO_C || defined __SUNPRO_CC
|
43
|
+
#define TNT_GCC_VERSION(major, minor) 0
|
44
|
+
#else
|
45
|
+
#define TNT_GCC_VERSION(major, minor) (__GNUC__ > (major) || \
|
46
|
+
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
|
47
|
+
#endif
|
48
|
+
|
49
|
+
#if !defined(__has_builtin)
|
50
|
+
#define __has_builtin(x) 0 /* clang */
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#if TNT_GCC_VERSION(2, 9) || __has_builtin(__builtin_expect)
|
54
|
+
#define tntlikely(x) __builtin_expect(!!(x), 1)
|
55
|
+
#define tntunlikely(x) __builtin_expect(!!(x), 0)
|
56
|
+
#else
|
57
|
+
#define tntlikely(x) (x)
|
58
|
+
#define tntunlikely(x) (x)
|
59
|
+
#endif
|
60
|
+
|
61
|
+
/**
|
62
|
+
* \brief basic allocation function type
|
63
|
+
*
|
64
|
+
* \param ptr pointer to allocation/deallocation block
|
65
|
+
* \param size size of block to allocat/reallocate
|
66
|
+
*
|
67
|
+
* \retval pointer to newly alloced/realloced block
|
68
|
+
* \retval NULL on error/free
|
69
|
+
*/
|
70
|
+
typedef void *(tnt_allocator_t)(void *ptr, size_t size);
|
71
|
+
|
72
|
+
/**
|
73
|
+
* \brief initialize memory allocation function
|
74
|
+
*/
|
75
|
+
void *
|
76
|
+
tnt_mem_init(tnt_allocator_t alloc);
|
77
|
+
|
78
|
+
/**
|
79
|
+
* \brief Internal function
|
80
|
+
*/
|
81
|
+
void *
|
82
|
+
tnt_mem_alloc(size_t size);
|
83
|
+
|
84
|
+
/**
|
85
|
+
* \brief Internal function
|
86
|
+
*/
|
87
|
+
void *
|
88
|
+
tnt_mem_realloc(void *ptr, size_t size);
|
89
|
+
|
90
|
+
/**
|
91
|
+
* \brief Internal function
|
92
|
+
*/
|
93
|
+
char *
|
94
|
+
tnt_mem_dup(char *sz);
|
95
|
+
|
96
|
+
/**
|
97
|
+
* \brief Internal function
|
98
|
+
*/
|
99
|
+
void
|
100
|
+
tnt_mem_free(void *ptr);
|
101
|
+
|
102
|
+
#endif /* TNT_MEM_H_INCLUDED */
|
@@ -0,0 +1,242 @@
|
|
1
|
+
#ifndef TNT_NET_H_INCLUDED
|
2
|
+
#define TNT_NET_H_INCLUDED
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Redistribution and use in source and binary forms, with or
|
6
|
+
* without modification, are permitted provided that the following
|
7
|
+
* conditions are met:
|
8
|
+
*
|
9
|
+
* 1. Redistributions of source code must retain the above
|
10
|
+
* copyright notice, this list of conditions and the
|
11
|
+
* following disclaimer.
|
12
|
+
*
|
13
|
+
* 2. Redistributions in binary form must reproduce the above
|
14
|
+
* copyright notice, this list of conditions and the following
|
15
|
+
* disclaimer in the documentation and/or other materials
|
16
|
+
* provided with the distribution.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
|
19
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
20
|
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
22
|
+
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
26
|
+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
29
|
+
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
30
|
+
* SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
/**
|
34
|
+
* \file tnt_net.h
|
35
|
+
* \brief Basic tarantool client library header for network stream layer
|
36
|
+
*/
|
37
|
+
|
38
|
+
#ifdef __cplusplus
|
39
|
+
extern "C" {
|
40
|
+
#endif
|
41
|
+
|
42
|
+
#include <stdint.h>
|
43
|
+
#include <stdarg.h>
|
44
|
+
|
45
|
+
#include <sys/types.h>
|
46
|
+
#include <sys/time.h>
|
47
|
+
|
48
|
+
#include <tarantool/tnt_opt.h>
|
49
|
+
#include <tarantool/tnt_iob.h>
|
50
|
+
|
51
|
+
/**
|
52
|
+
* \brief Internal error codes
|
53
|
+
*/
|
54
|
+
enum tnt_error {
|
55
|
+
TNT_EOK, /*!< Everything is OK */
|
56
|
+
TNT_EFAIL, /*!< Fail */
|
57
|
+
TNT_EMEMORY, /*!< Memory allocation failed */
|
58
|
+
TNT_ESYSTEM, /*!< System error */
|
59
|
+
TNT_EBIG, /*!< Buffer is too big */
|
60
|
+
TNT_ESIZE, /*!< Bad buffer size */
|
61
|
+
TNT_ERESOLVE, /*!< gethostbyname(2) failed */
|
62
|
+
TNT_ETMOUT, /*!< Operation timeout */
|
63
|
+
TNT_EBADVAL, /*!< Bad argument (value) */
|
64
|
+
TNT_ELOGIN, /*!< Failed to login */
|
65
|
+
TNT_LAST /*!< Not an error */
|
66
|
+
};
|
67
|
+
|
68
|
+
/**
|
69
|
+
* \brief Network stream structure
|
70
|
+
*/
|
71
|
+
struct tnt_stream_net {
|
72
|
+
struct tnt_opt opt; /*!< Options for connection */
|
73
|
+
int connected; /*!< Connection status. 1 - true, 0 - false */
|
74
|
+
int fd; /*!< fd of connection */
|
75
|
+
struct tnt_iob sbuf; /*!< Send buffer */
|
76
|
+
struct tnt_iob rbuf; /*!< Recv buffer */
|
77
|
+
enum tnt_error error; /*!< If retval == -1, then error is set. */
|
78
|
+
int errno_; /*!< If TNT_ESYSTEM then errno_ is set */
|
79
|
+
char *greeting; /*!< Pointer to greeting, if connected */
|
80
|
+
struct tnt_schema *schema; /*!< Collation for space/index string<->number */
|
81
|
+
int inited; /*!< 1 if iob/schema were allocated */
|
82
|
+
};
|
83
|
+
|
84
|
+
/*!
|
85
|
+
* \internal
|
86
|
+
* \brief Cast tnt_stream to tnt_net
|
87
|
+
*/
|
88
|
+
#define TNT_SNET_CAST(S) ((struct tnt_stream_net*)(S)->data)
|
89
|
+
|
90
|
+
/**
|
91
|
+
* \brief Create tnt_net stream instance
|
92
|
+
*
|
93
|
+
* \param s stream pointer, maybe NULL
|
94
|
+
*
|
95
|
+
* If stream pointer is NULL, then new stream will be created.
|
96
|
+
*
|
97
|
+
* \returns stream pointer
|
98
|
+
* \retval NULL oom
|
99
|
+
*
|
100
|
+
* \code{.c}
|
101
|
+
* struct tnt_stream *tnt = tnt_net(NULL);
|
102
|
+
* assert(tnt);
|
103
|
+
* assert(tnt_set(s, TNT_OPT_URI, "login:passw@localhost:3302") != -1);
|
104
|
+
* assert(tnt_connect(s) != -1);
|
105
|
+
* ...
|
106
|
+
* tnt_close(s);
|
107
|
+
* \endcode
|
108
|
+
*/
|
109
|
+
struct tnt_stream *
|
110
|
+
tnt_net(struct tnt_stream *s);
|
111
|
+
|
112
|
+
/**
|
113
|
+
* \brief Set options for connection
|
114
|
+
*
|
115
|
+
* \param s stream pointer
|
116
|
+
* \param opt option to set
|
117
|
+
* \param ... option value
|
118
|
+
*
|
119
|
+
* \returns status
|
120
|
+
* \retval -1 error
|
121
|
+
* \retval 0 ok
|
122
|
+
* \sa enum tnt_opt_type
|
123
|
+
*
|
124
|
+
* \code{.c}
|
125
|
+
* assert(tnt_set(s, TNT_OPT_SEND_BUF, 16*1024) != -1);
|
126
|
+
* assert(tnt_set(s, TNT_OPT_RECV_BUF, 16*1024) != -1);
|
127
|
+
* assert(tnt_set(s, TNT_OPT_URI, "login:passw@localhost:3302") != -1);
|
128
|
+
* \endcode
|
129
|
+
*
|
130
|
+
* \note
|
131
|
+
* URI format:
|
132
|
+
* * "[login:password@]host:port" for tcp sockets
|
133
|
+
* * "[login:password@]/tmp/socket_path.sock" for unix sockets
|
134
|
+
* \sa enum tnt_opt_type
|
135
|
+
*/
|
136
|
+
int
|
137
|
+
tnt_set(struct tnt_stream *s, int opt, ...);
|
138
|
+
|
139
|
+
/*!
|
140
|
+
* \internal
|
141
|
+
* \brief Initialize network stream
|
142
|
+
*
|
143
|
+
* It must happened before connection, but after options are set.
|
144
|
+
* 1) creation of tnt_iob's (sbuf,rbuf)
|
145
|
+
* 2) schema creation
|
146
|
+
*
|
147
|
+
* \param s stream for initialization
|
148
|
+
*
|
149
|
+
* \returns status
|
150
|
+
* \retval 0 ok
|
151
|
+
* \retval -1 error (oom/einval)
|
152
|
+
*/
|
153
|
+
int
|
154
|
+
tnt_init(struct tnt_stream *s);
|
155
|
+
|
156
|
+
/**
|
157
|
+
* \brief Connect to tarantool with preconfigured and allocated settings
|
158
|
+
*
|
159
|
+
* \param s stream pointer
|
160
|
+
*
|
161
|
+
* \retval 0 ok
|
162
|
+
* \retval -1 error (network/oom)
|
163
|
+
*/
|
164
|
+
int
|
165
|
+
tnt_connect(struct tnt_stream *s);
|
166
|
+
|
167
|
+
/**
|
168
|
+
* \brief Close connection
|
169
|
+
* \param s stream pointer
|
170
|
+
*/
|
171
|
+
void
|
172
|
+
tnt_close(struct tnt_stream *s);
|
173
|
+
|
174
|
+
/**
|
175
|
+
* \brief Send written to buffer queries
|
176
|
+
*
|
177
|
+
* \param s tnt_stream
|
178
|
+
*
|
179
|
+
* \returns number of bytes written to socket
|
180
|
+
* \retval -1 on network error
|
181
|
+
*/
|
182
|
+
ssize_t
|
183
|
+
tnt_flush(struct tnt_stream *s);
|
184
|
+
|
185
|
+
/**
|
186
|
+
* \brief Get tnt_net stream fd
|
187
|
+
*/
|
188
|
+
int
|
189
|
+
tnt_fd(struct tnt_stream *s);
|
190
|
+
|
191
|
+
/**
|
192
|
+
* \brief Error accessor for tnt_net stream
|
193
|
+
*/
|
194
|
+
enum tnt_error
|
195
|
+
tnt_error(struct tnt_stream *s);
|
196
|
+
|
197
|
+
/**
|
198
|
+
* \brief Format error as string
|
199
|
+
*/
|
200
|
+
char *
|
201
|
+
tnt_strerror(struct tnt_stream *s);
|
202
|
+
|
203
|
+
/**
|
204
|
+
* \brief Get last errno on socket
|
205
|
+
*/
|
206
|
+
int
|
207
|
+
tnt_errno(struct tnt_stream *s);
|
208
|
+
|
209
|
+
/**
|
210
|
+
* \brief Flush space/index schema and get it from server
|
211
|
+
*
|
212
|
+
* \param s stream pointer
|
213
|
+
*
|
214
|
+
* \returns result
|
215
|
+
* \retval -1 error
|
216
|
+
* \retval 0 ok
|
217
|
+
*/
|
218
|
+
int
|
219
|
+
tnt_reload_schema(struct tnt_stream *s);
|
220
|
+
|
221
|
+
/**
|
222
|
+
* \brief Get space number from space name
|
223
|
+
*
|
224
|
+
* \returns space number
|
225
|
+
* \retval -1 error
|
226
|
+
*/
|
227
|
+
int tnt_get_spaceno(struct tnt_stream *s, const char *space, size_t space_len);
|
228
|
+
|
229
|
+
/**
|
230
|
+
* \brief Get index number from index name and spaceid
|
231
|
+
*
|
232
|
+
* \returns index number
|
233
|
+
* \retval -1 error
|
234
|
+
*/
|
235
|
+
int tnt_get_indexno(struct tnt_stream *s, int spaceno, const char *index,
|
236
|
+
size_t index_len);
|
237
|
+
|
238
|
+
#ifdef __cplusplus
|
239
|
+
}
|
240
|
+
#endif
|
241
|
+
|
242
|
+
#endif /* TNT_NET_H_INCLUDED */
|