libcouchbase 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -0,0 +1,228 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2013 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #ifndef LCB_STRING_H
19
+ #define LCB_STRING_H
20
+
21
+ #include <libcouchbase/couchbase.h>
22
+ #include <stdarg.h>
23
+
24
+ #include "config.h"
25
+ #include "assert.h"
26
+ #include "ringbuffer.h"
27
+
28
+ /**
29
+ * Simple string type.
30
+ *
31
+ * This structure is designed mainly for ease of use when dealing with actual
32
+ * "string" data - i.e. data which must be null-terminated and contiguous.
33
+ *
34
+ * This won't replace the ringbuffer structure as this string's removal and
35
+ * copying operations are comparatively expensive.
36
+ *
37
+ * Note that all API functions which update the position of the buffer ALSO
38
+ * add a trailing NUL byte at the end.
39
+ */
40
+ typedef struct lcb_string_st {
41
+ /** Buffer that's allocated */
42
+ char *base;
43
+
44
+ /** Number of bytes allocated */
45
+ lcb_size_t nalloc;
46
+
47
+ /** Number of bytes used */
48
+ lcb_size_t nused;
49
+ #ifdef __cplusplus
50
+ typedef char *iterator;
51
+ typedef const char *const_iterator;
52
+
53
+ iterator begin() { return base; };
54
+ iterator end() { return base + nused; }
55
+ const_iterator begin() const { return base; }
56
+ const_iterator end() const { return base + nused; }
57
+ size_t size() const { return nused; }
58
+ size_t capacity() const { return nalloc; }
59
+ const char *c_str() const { return base; }
60
+
61
+ inline void insert(iterator p, const char *first, const char *last);
62
+ #endif
63
+ } lcb_string;
64
+
65
+ #ifdef __cplusplus
66
+ extern "C" {
67
+ #endif
68
+
69
+ int lcb_string_init(lcb_string *str);
70
+
71
+ /**
72
+ * Free any storage associated with the string. The string's state will be
73
+ * empty as if string_init() had just been called.
74
+ */
75
+ void lcb_string_release(lcb_string *str);
76
+
77
+ /**
78
+ * Clear the contents of the string, but don't free the underlying buffer
79
+ */
80
+ void lcb_string_clear(lcb_string *str);
81
+
82
+
83
+ /**
84
+ * Indicate that bytes have been added to the string. This is used in conjunction
85
+ * with reserve(). As such, the number of bytes added should not exceed the
86
+ * number of bytes passed to reserver.
87
+ *
88
+ * @param str the string
89
+ * @param nbytes the number of bytes added
90
+ */
91
+ void lcb_string_added(lcb_string *str, lcb_size_t nbytes);
92
+
93
+ /**
94
+ * Reserve an amount of free bytes within the string. When this is done,
95
+ * up to @c size bytes may be added to the string starting at @c base+str->nbytes
96
+ */
97
+ int lcb_string_reserve(lcb_string *str, lcb_size_t size);
98
+
99
+
100
+ /**
101
+ * Adds data to the string.
102
+ * @param str the string to append to
103
+ * @param data the data to copy
104
+ * @param size the size of data to copy
105
+ */
106
+ int lcb_string_append(lcb_string *str, const void *data, lcb_size_t size);
107
+
108
+ /**
109
+ * Adds a C-style string
110
+ * @param str the target lcb_string
111
+ * @param zstr a NUL-terminated string to add
112
+ */
113
+ int lcb_string_appendz(lcb_string *str, const char *zstr);
114
+
115
+
116
+ /**
117
+ * Appends a list of pointer-length pairs. Useful if you need to concatenate
118
+ * many small buffers
119
+ * @param str The string to append to. This should be followed by a list of
120
+ * `pointer, size` arguments (where `size` is `size_t`). If the length is
121
+ * `-1` then `strlen(pointer)` will be called to determine the length.
122
+ *
123
+ * A terminal `NULL` should be placed at the end of the argument list
124
+ *
125
+ * @return 0 if appended, nonzero on memory error
126
+ */
127
+ int lcb_string_appendv(lcb_string *str, ...);
128
+
129
+ /**
130
+ * Adds a string from a ringbuffer structure. This copies the contents
131
+ * of the ringbuffer into a string.
132
+ * @param str the target string
133
+ * @param rb the source ringbuffer
134
+ * @param rbadvance whether to advance the ringbuffer's read head
135
+ */
136
+ int lcb_string_rbappend(lcb_string *str, ringbuffer_t *rb, int rbadvance);
137
+
138
+ /**
139
+ * Removes bytes from the end of the string. The resultant string will be
140
+ * NUL-terminated
141
+ * @param str the string to operate on
142
+ * @param to_remove the number of bytes to trim from the end
143
+ */
144
+ void lcb_string_erase_end(lcb_string *str, lcb_size_t to_remove);
145
+
146
+
147
+ /**
148
+ * Removes bytes from the beginning of the string. The resultant string will
149
+ * be NUL-terminated.
150
+ * @param str the string to operate on
151
+ * @param to_remove the number of bytes to remove from the beginning of
152
+ * the string.
153
+ */
154
+ void lcb_string_erase_beginning(lcb_string *str, lcb_size_t to_remove);
155
+
156
+ /**
157
+ * Transfers ownership of the underlying buffer contained within the structure
158
+ * 'to' to the structure 'from', as such, 'from' becomes a newly initialized
159
+ * empty string structure and 'to' contains the existing buffer.
160
+ *
161
+ * @param from the string which contains the existing buffer
162
+ * @param to a new string structure which contains no buffer. It will receive
163
+ * from's buffer
164
+ */
165
+ void lcb_string_transfer(lcb_string *from, lcb_string *to);
166
+
167
+ /**
168
+ * Inserts a string at a given position
169
+ * @param str the string object
170
+ * @param at position at which to insert
171
+ * @param src the string to insert
172
+ * @param len length of string to insert
173
+ */
174
+ int lcb_string_insert(lcb_string *str, size_t at, const char *src, size_t len);
175
+
176
+ #define lcb_string_tail(str) ((str)->base + (str)->nused)
177
+
178
+ #ifdef __cplusplus
179
+ }
180
+
181
+ #include <stdexcept>
182
+ #include <new>
183
+ void
184
+ lcb_string_st::insert(iterator p, const char *first, const char *last) {
185
+ size_t at = p - base;
186
+ size_t n = last - first;
187
+ if (lcb_string_insert(this, at, first, n) != 0) {
188
+ throw std::bad_alloc();
189
+ }
190
+ }
191
+
192
+ namespace lcb {
193
+ class AutoString : public lcb_string_st {
194
+ public:
195
+ AutoString() {
196
+ lcb_string_init(this);
197
+ }
198
+ ~AutoString() {
199
+ lcb_string_release(this);
200
+ }
201
+
202
+ char *take(size_t& len, size_t& cap) {
203
+ char *ret = base;
204
+ len = nused;
205
+ cap = nalloc;
206
+
207
+ base = NULL;
208
+ nalloc = 0;
209
+ nused = 0;
210
+ return ret;
211
+ }
212
+ char *take(size_t& len) {
213
+ size_t dummy;
214
+ return take(len, dummy);
215
+ }
216
+ char *take() {
217
+ size_t dummy;
218
+ return take(dummy, dummy);
219
+ }
220
+
221
+ private:
222
+ AutoString(lcb_string_st&);
223
+ AutoString(const lcb_string_st&);
224
+ };
225
+ }
226
+
227
+ #endif /** __cplusplus */
228
+ #endif /* LCB_STRING_H */
@@ -137,7 +137,6 @@ async_write(void *arg)
137
137
  {
138
138
  lcbio_CSSL *cs = arg;
139
139
  appdata_encode(cs);
140
- schedule_wants(cs);
141
140
  appdata_free_flushed(cs);
142
141
  }
143
142
 
@@ -156,9 +156,7 @@ iotssl_log_errors(lcbio_XSSL *xs)
156
156
  if (ERR_GET_LIB(curerr) == ERR_LIB_SSL) {
157
157
  switch (ERR_GET_REASON(curerr)) {
158
158
  case SSL_R_CERTIFICATE_VERIFY_FAILED:
159
- #ifdef SSL_R_MISSING_VERIFY_MESSAGE
160
159
  case SSL_R_MISSING_VERIFY_MESSAGE:
161
- #endif
162
160
  xs->errcode = LCB_SSL_CANTVERIFY;
163
161
  break;
164
162
 
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  #include "ssl_iot_common.h"
19
+ #include "simplestring.h"
19
20
  #include <openssl/err.h>
20
21
  /**
21
22
  * Event-Style SSL Wrapping.
@@ -0,0 +1,82 @@
1
+ /*
2
+ * Copyright 2015 Couchbase, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * Implementation of dynamic arrays or strings suitable for one or more than
19
+ * one element. If only a single element is used, extra memory is not allocated
20
+ * via malloc.
21
+ */
22
+
23
+ #include "simplestring.h"
24
+
25
+ #define LCB_SSOBUF_DECLARE(T) \
26
+ struct { \
27
+ unsigned count; \
28
+ union { \
29
+ lcb_string alloc; \
30
+ T single; \
31
+ } u;\
32
+ } \
33
+
34
+ #define LCB_SSOBUF_ALLOC(p, o, T) do { \
35
+ if ((o)->count == 0) { /* Only allocate a single element */ \
36
+ *(p) = &(o)->u.single; \
37
+ (o)->count++; \
38
+ } else if ((o)->count == 1) { /* Switch over to malloc */ \
39
+ T ssobuf__tmp = (o)->u.single; \
40
+ (o)->u.alloc.nused = 0; \
41
+ (o)->u.alloc.nalloc = 0; \
42
+ (o)->u.alloc.base = NULL; \
43
+ if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T) * 2)) { \
44
+ *(p) = NULL; \
45
+ } else { \
46
+ memcpy((o)->u.alloc.base, &ssobuf__tmp, sizeof(T)); \
47
+ lcb_string_added(&(o)->u.alloc, sizeof(T)); \
48
+ *(p) = (T*) ((o)->u.alloc.base + (o)->u.alloc.nused); \
49
+ lcb_string_added(&(o)->u.alloc, sizeof(T)); \
50
+ } \
51
+ (o)->count++; \
52
+ } else if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T))) { \
53
+ *(p) = NULL; \
54
+ } else { \
55
+ *(p) = (T*) ((o)->u.alloc.base + (o)->u.alloc.nused); \
56
+ lcb_string_added(&(o)->u.alloc, sizeof(T)); \
57
+ (o)->count++; \
58
+ } \
59
+ } while (0);
60
+
61
+ #define LCB_SSOBUF_ALLOC_N(p, o, T, n) do { \
62
+ if (n == 1) { \
63
+ LCB_SSOBUF_ALLOC(p, o, T); \
64
+ } else if (n > 1) { \
65
+ if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T) * (n) )) { \
66
+ *(p) = NULL; \
67
+ } else { \
68
+ lcb_string_added(&(o)->u.alloc, sizeof(T) * (n) ); \
69
+ *(p) = (T*)(o)->u.alloc.base; \
70
+ (o)->count = n; \
71
+ } \
72
+ } \
73
+ } while (0);
74
+
75
+ #define LCB_SSOBUF_CLEAN(o) do { \
76
+ if ((o)->count > 1) { \
77
+ lcb_string_release(&(o)->u.alloc); \
78
+ } \
79
+ } while (0);
80
+
81
+ #define LCB_SSOBUF_ARRAY(o, t) \
82
+ ((o)->count > 1 ? ((t*)(o)->u.alloc.base) : &(o)->u.single)
@@ -40,11 +40,11 @@
40
40
 
41
41
  #define TRACE_BEGIN_COMMON(TGT, req, cmd, ...) \
42
42
  TGT((req)->request.opaque, ntohs((req)->request.vbucket), (req)->request.opcode, \
43
- (const char *)((cmd)->key.contig.bytes), (cmd)->key.contig.nbytes, ## __VA_ARGS__)
43
+ (cmd)->key.contig.bytes, (cmd)->key.contig.nbytes, ## __VA_ARGS__)
44
44
 
45
45
  #define TRACE_BEGIN_SIMPLE(TGT, req, cmd) \
46
46
  TGT((req)->request.opaque, ntohs((req)->request.vbucket), (req)->request.opcode, \
47
- (const char *)(cmd)->key.contig.bytes, (cmd)->key.contig.nbytes)
47
+ (cmd)->key.contig.bytes, (cmd)->key.contig.nbytes)
48
48
 
49
49
  #define TRACE_END_COMMON(TGT, mcresp, resp, ...) \
50
50
  TGT(mcresp->opaque(), 0, mcresp->opcode(), (resp)->rc, (const char *)(resp)->key, (resp)->nkey, \
@@ -58,7 +58,7 @@
58
58
 
59
59
  #define TRACE_GET_END(mcresp, resp) \
60
60
  TRACE(TRACE_END_COMMON(LIBCOUCHBASE_GET_END, mcresp, resp, \
61
- (const char*)(resp)->value, (resp)->nvalue, (resp)->itmflags, (resp)->cas, \
61
+ (char*)(resp)->value, (resp)->nvalue, (resp)->itmflags, (resp)->cas, \
62
62
  mcresp->datatype()))
63
63
 
64
64
  #define TRACE_UNLOCK_BEGIN(req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_UNLOCK_BEGIN, req, cmd))
@@ -66,7 +66,7 @@
66
66
 
67
67
  #define TRACE_STORE_BEGIN(req, cmd) \
68
68
  TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_STORE_BEGIN, req, cmd, \
69
- (const char *)( (cmd)->value.vtype == LCB_KV_IOV ? NULL : (cmd)->value.u_buf.contig.bytes ),\
69
+ ( (cmd)->value.vtype == LCB_KV_IOV ? NULL : (cmd)->value.u_buf.contig.bytes ),\
70
70
  ( (cmd)->value.vtype == LCB_KV_IOV ? 0 : (cmd)->value.u_buf.contig.nbytes ),\
71
71
  (cmd)->flags, (cmd)->cas, (req)->request.datatype, (cmd)->exptime))
72
72
 
@@ -26,6 +26,7 @@
26
26
  #include "json-inl.h"
27
27
  #include "hash.h"
28
28
  #include "crc32.h"
29
+ #include "simplestring.h"
29
30
 
30
31
  #define STRINGIFY_(X) #X
31
32
  #define STRINGIFY(X) STRINGIFY_(X)
@@ -2,53 +2,56 @@
2
2
  #include "internal.h"
3
3
  #include "sllist-inl.h"
4
4
 
5
- using namespace lcb::docreq;
6
-
7
5
  static void docreq_handler(void *arg);
8
- static void invoke_pending(Queue*);
6
+ static void invoke_pending(lcb_DOCQUEUE*);
9
7
  static void doc_callback(lcb_t,int, const lcb_RESPBASE *);
10
8
 
11
9
  #define MAX_PENDING_DOCREQ 10
12
10
  #define MIN_SCHED_SIZE 5
13
11
  #define DOCQ_DELAY_US 200000
14
12
 
15
- Queue::Queue(lcb_t instance_)
16
- : instance(instance_),
17
- parent(NULL),
18
- timer(lcbio_timer_new(instance->iotable, this, docreq_handler)),
19
- cb_ready(NULL), cb_throttle(NULL),
20
- n_awaiting_schedule(0),
21
- n_awaiting_response(0),
22
- max_pending_response(MAX_PENDING_DOCREQ),
23
- min_batch_size(MIN_SCHED_SIZE),
24
- cancelled(false),
25
- refcount(1)
26
- {
27
-
28
- memset(&pending_gets, 0, sizeof pending_gets);
29
- memset(&cb_queue, 0, sizeof cb_queue);
13
+ #define DOCQ_REF(q) (q)->refcount++
14
+ #define DOCQ_UNREF(q) if (!--(q)->refcount) { docq_free(q); }
15
+
16
+ lcb_DOCQUEUE *
17
+ lcbdocq_create(lcb_t instance)
18
+ {
19
+ lcb_DOCQUEUE *q = calloc(1, sizeof *q);
20
+ q->timer = lcbio_timer_new(instance->iotable, q, docreq_handler);
21
+ q->refcount = 1;
22
+ q->instance = instance;
23
+ q->max_pending_response = MAX_PENDING_DOCREQ;
24
+ q->min_batch_size = MIN_SCHED_SIZE;
25
+ return q;
30
26
  }
31
27
 
32
- Queue::~Queue() {
33
- cancel();
34
- lcbio_timer_destroy(timer);
28
+ static void
29
+ docq_free(lcb_DOCQUEUE *q)
30
+ {
31
+ lcbdocq_cancel(q);
32
+ lcbio_timer_destroy(q->timer);
33
+ free(q);
35
34
  }
36
35
 
37
- void Queue::unref() {
38
- if (!--refcount) {
39
- delete this;
40
- }
36
+ void
37
+ lcbdocq_unref(lcb_DOCQUEUE *q)
38
+ {
39
+ DOCQ_UNREF(q);
41
40
  }
42
41
 
43
- void Queue::cancel() {
44
- cancelled = true;
42
+ void
43
+ lcbdocq_cancel(lcb_DOCQUEUE *q)
44
+ {
45
+ if (!q->cancelled) {
46
+ q->cancelled = 1;
47
+ }
45
48
  }
46
49
 
47
50
  /* Calling this function ensures that the request will be scheduled in due
48
51
  * time. This may be done at the next event loop iteration, or after a delay
49
52
  * depending on how many items are actually found within the queue. */
50
53
  static void
51
- docq_poke(Queue *q)
54
+ docq_poke(lcb_DOCQUEUE *q)
52
55
  {
53
56
  if (q->n_awaiting_response < q->max_pending_response) {
54
57
  if (q->n_awaiting_schedule > q->min_batch_size) {
@@ -62,26 +65,27 @@ docq_poke(Queue *q)
62
65
  }
63
66
  }
64
67
 
65
- void Queue::add(DocRequest *req)
68
+ void
69
+ lcbdocq_add(lcb_DOCQUEUE *q, lcb_DOCQREQ *req)
66
70
  {
67
- sllist_append(&pending_gets, &req->slnode);
68
- n_awaiting_schedule++;
69
- req->parent = this;
71
+ sllist_append(&q->pending_gets, &req->slnode);
72
+ q->n_awaiting_schedule++;
73
+ req->parent = q;
70
74
  req->ready = 0;
71
- ref();
72
- docq_poke(this);
75
+ DOCQ_REF(q);
76
+ docq_poke(q);
73
77
  }
74
78
 
75
79
  static void
76
80
  docreq_handler(void *arg)
77
81
  {
78
- Queue *q = reinterpret_cast<Queue*>(arg);
82
+ lcb_DOCQUEUE *q = arg;
79
83
  sllist_iterator iter;
80
84
  lcb_t instance = q->instance;
81
85
 
82
86
  lcb_sched_enter(instance);
83
87
  SLLIST_ITERFOR(&q->pending_gets, &iter) {
84
- DocRequest *cont = SLLIST_ITEM(iter.cur, DocRequest, slnode);
88
+ lcb_DOCQREQ *cont = SLLIST_ITEM(iter.cur, lcb_DOCQREQ, slnode);
85
89
 
86
90
  if (q->n_awaiting_response > q->max_pending_response) {
87
91
  lcbio_timer_rearm(q->timer, DOCQ_DELAY_US);
@@ -132,12 +136,13 @@ docreq_handler(void *arg)
132
136
  /* Invokes the callback on all requests which are ready, until a request which
133
137
  * is not yet ready is reached. */
134
138
  static void
135
- invoke_pending(Queue *q)
139
+ invoke_pending(lcb_DOCQUEUE *q)
136
140
  {
137
141
  sllist_iterator iter = { NULL };
138
- q->ref();
142
+
143
+ DOCQ_REF(q);
139
144
  SLLIST_ITERFOR(&q->cb_queue, &iter) {
140
- DocRequest *dreq = SLLIST_ITEM(iter.cur, DocRequest, slnode);
145
+ lcb_DOCQREQ *dreq = SLLIST_ITEM(iter.cur, lcb_DOCQREQ, slnode);
141
146
  void *bufh = NULL;
142
147
 
143
148
  if (dreq->ready == 0) {
@@ -152,21 +157,21 @@ invoke_pending(Queue *q)
152
157
 
153
158
  q->cb_ready(q, dreq);
154
159
  if (bufh) {
155
- lcb_backbuf_unref(reinterpret_cast<lcb_BACKBUF>(bufh));
160
+ lcb_backbuf_unref(bufh);
156
161
  }
157
- q->unref();
162
+ DOCQ_UNREF(q);
158
163
  }
159
- q->unref();
164
+ DOCQ_UNREF(q);
160
165
  }
161
166
 
162
167
  static void
163
- doc_callback(lcb_t, int, const lcb_RESPBASE *rb)
168
+ doc_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
164
169
  {
165
170
  const lcb_RESPGET *rg = (const lcb_RESPGET *)rb;
166
- DocRequest *dreq = reinterpret_cast<DocRequest*>(rb->cookie);
167
- Queue *q = dreq->parent;
171
+ lcb_DOCQREQ *dreq = rb->cookie;
172
+ lcb_DOCQUEUE *q = dreq->parent;
168
173
 
169
- q->ref();
174
+ DOCQ_REF(q);
170
175
 
171
176
  q->n_awaiting_response--;
172
177
  dreq->docresp = *rg;
@@ -177,12 +182,13 @@ doc_callback(lcb_t, int, const lcb_RESPBASE *rb)
177
182
  /* Reference the response data, since we might not be invoking this right
178
183
  * away */
179
184
  if (rg->rc == LCB_SUCCESS) {
180
- lcb_backbuf_ref(reinterpret_cast<lcb_BACKBUF>(dreq->docresp.bufh));
185
+ lcb_backbuf_ref(dreq->docresp.bufh);
181
186
  }
182
187
 
183
188
  /* Ensure the invoke_pending doesn't destroy us */
184
189
  invoke_pending(q);
185
190
  docq_poke(q);
186
191
 
187
- q->unref();
192
+ DOCQ_UNREF(q);
193
+ (void)instance; (void)cbtype;
188
194
  }