memcached 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +206 -12
  3. data/Rakefile +32 -1
  4. data/ext/extconf.rb +10 -35
  5. data/ext/libmemcached-0.32/AUTHORS +7 -0
  6. data/ext/libmemcached-0.32/COPYING +32 -0
  7. data/ext/libmemcached-0.32/ChangeLog +303 -0
  8. data/ext/libmemcached-0.32/INSTALL +302 -0
  9. data/ext/libmemcached-0.32/Makefile.am +36 -0
  10. data/ext/libmemcached-0.32/Makefile.in +828 -0
  11. data/ext/libmemcached-0.32/NEWS +1 -0
  12. data/ext/libmemcached-0.32/README +33 -0
  13. data/ext/libmemcached-0.32/THANKS +14 -0
  14. data/ext/libmemcached-0.32/TODO +11 -0
  15. data/ext/libmemcached-0.32/aclocal.m4 +1852 -0
  16. data/ext/libmemcached-0.32/clients/Makefile.am +73 -0
  17. data/ext/libmemcached-0.32/clients/Makefile.in +770 -0
  18. data/ext/libmemcached-0.32/clients/client_options.h +32 -0
  19. data/ext/libmemcached-0.32/clients/execute.c +64 -0
  20. data/ext/libmemcached-0.32/clients/execute.h +5 -0
  21. data/ext/libmemcached-0.32/clients/generator.c +74 -0
  22. data/ext/libmemcached-0.32/clients/generator.h +20 -0
  23. data/ext/libmemcached-0.32/clients/memcat.c +178 -0
  24. data/ext/libmemcached-0.32/clients/memcp.c +251 -0
  25. data/ext/libmemcached-0.32/clients/memdump.c +170 -0
  26. data/ext/libmemcached-0.32/clients/memerror.c +80 -0
  27. data/ext/libmemcached-0.32/clients/memflush.c +143 -0
  28. data/ext/libmemcached-0.32/clients/memrm.c +160 -0
  29. data/ext/libmemcached-0.32/clients/memslap.c +441 -0
  30. data/ext/libmemcached-0.32/clients/memstat.c +326 -0
  31. data/ext/libmemcached-0.32/clients/utilities.c +207 -0
  32. data/ext/libmemcached-0.32/clients/utilities.h +41 -0
  33. data/ext/libmemcached-0.32/config.h.in +252 -0
  34. data/ext/libmemcached-0.32/config/compile +143 -0
  35. data/ext/libmemcached-0.32/config/config.guess +1561 -0
  36. data/ext/libmemcached-0.32/config/config.rpath +666 -0
  37. data/ext/libmemcached-0.32/config/config.sub +1686 -0
  38. data/ext/libmemcached-0.32/config/depcomp +630 -0
  39. data/ext/libmemcached-0.32/config/install-sh +520 -0
  40. data/ext/libmemcached-0.32/config/ltmain.sh +8406 -0
  41. data/ext/libmemcached-0.32/config/missing +376 -0
  42. data/ext/libmemcached-0.32/configure +23048 -0
  43. data/ext/libmemcached-0.32/configure.ac +122 -0
  44. data/ext/libmemcached-0.32/docs/Makefile.am +415 -0
  45. data/ext/libmemcached-0.32/docs/Makefile.in +918 -0
  46. data/ext/libmemcached-0.32/docs/libmemcached.pod +123 -0
  47. data/ext/libmemcached-0.32/docs/libmemcached_examples.pod +115 -0
  48. data/ext/libmemcached-0.32/docs/libmemcachedutil.pod +40 -0
  49. data/ext/libmemcached-0.32/docs/memcached_analyze.pod +52 -0
  50. data/ext/libmemcached-0.32/docs/memcached_auto.pod +97 -0
  51. data/ext/libmemcached-0.32/docs/memcached_behavior.pod +224 -0
  52. data/ext/libmemcached-0.32/docs/memcached_callback.pod +123 -0
  53. data/ext/libmemcached-0.32/docs/memcached_create.pod +61 -0
  54. data/ext/libmemcached-0.32/docs/memcached_delete.pod +54 -0
  55. data/ext/libmemcached-0.32/docs/memcached_dump.pod +53 -0
  56. data/ext/libmemcached-0.32/docs/memcached_flush.pod +46 -0
  57. data/ext/libmemcached-0.32/docs/memcached_flush_buffers.pod +42 -0
  58. data/ext/libmemcached-0.32/docs/memcached_generate_hash_value.pod +57 -0
  59. data/ext/libmemcached-0.32/docs/memcached_get.pod +161 -0
  60. data/ext/libmemcached-0.32/docs/memcached_memory_allocators.pod +73 -0
  61. data/ext/libmemcached-0.32/docs/memcached_pool.pod +77 -0
  62. data/ext/libmemcached-0.32/docs/memcached_quit.pod +47 -0
  63. data/ext/libmemcached-0.32/docs/memcached_sasl.pod +63 -0
  64. data/ext/libmemcached-0.32/docs/memcached_server_st.pod +75 -0
  65. data/ext/libmemcached-0.32/docs/memcached_servers.pod +102 -0
  66. data/ext/libmemcached-0.32/docs/memcached_set.pod +187 -0
  67. data/ext/libmemcached-0.32/docs/memcached_stats.pod +82 -0
  68. data/ext/libmemcached-0.32/docs/memcached_strerror.pod +46 -0
  69. data/ext/libmemcached-0.32/docs/memcached_user_data.pod +49 -0
  70. data/ext/libmemcached-0.32/docs/memcached_verbosity.pod +41 -0
  71. data/ext/libmemcached-0.32/docs/memcached_version.pod +56 -0
  72. data/ext/libmemcached-0.32/docs/memcat.pod +37 -0
  73. data/ext/libmemcached-0.32/docs/memcp.pod +40 -0
  74. data/ext/libmemcached-0.32/docs/memdump.pod +31 -0
  75. data/ext/libmemcached-0.32/docs/memerror.pod +30 -0
  76. data/ext/libmemcached-0.32/docs/memflush.pod +35 -0
  77. data/ext/libmemcached-0.32/docs/memrm.pod +34 -0
  78. data/ext/libmemcached-0.32/docs/memslap.pod +33 -0
  79. data/ext/libmemcached-0.32/docs/memstat.pod +35 -0
  80. data/ext/libmemcached-0.32/libmemcached/Makefile.am +107 -0
  81. data/ext/libmemcached-0.32/libmemcached/Makefile.in +1050 -0
  82. data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
  83. data/ext/libmemcached-0.32/libmemcached/common.h +183 -0
  84. data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
  85. data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
  86. data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
  87. data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
  88. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +28 -0
  89. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +78 -0
  90. data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
  91. data/ext/libmemcached-0.32/libmemcached/memcached.c +152 -0
  92. data/ext/libmemcached-0.32/libmemcached/memcached.h +302 -0
  93. data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
  94. data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
  95. data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +366 -0
  96. data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
  97. data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
  98. data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
  99. data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +285 -0
  100. data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
  101. data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
  102. data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +361 -0
  103. data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +145 -0
  104. data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
  105. data/ext/libmemcached-0.32/libmemcached/memcached_do.c +34 -0
  106. data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
  107. data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
  108. data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
  109. data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +22 -0
  110. data/ext/libmemcached-0.32/libmemcached/memcached_get.c +495 -0
  111. data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
  112. data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
  113. data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
  114. data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
  115. data/ext/libmemcached-0.32/libmemcached/memcached_io.c +547 -0
  116. data/ext/libmemcached-0.32/libmemcached/memcached_io.h +59 -0
  117. data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
  118. data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
  119. data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
  120. data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
  121. data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
  122. data/ext/libmemcached-0.32/libmemcached/memcached_response.c +528 -0
  123. data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
  124. data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
  125. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
  126. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
  127. data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
  128. data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
  129. data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +454 -0
  130. data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
  131. data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
  132. data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
  133. data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
  134. data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
  135. data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
  136. data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
  137. data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
  138. data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
  139. data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
  140. data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
  141. data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
  142. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
  143. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +602 -0
  144. data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
  145. data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
  146. data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
  147. data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
  148. data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
  149. data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
  150. data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
  151. data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
  152. data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
  153. data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
  154. data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
  155. data/ext/libmemcached-0.32/m4/libtool.m4 +7360 -0
  156. data/ext/libmemcached-0.32/m4/ltoptions.m4 +368 -0
  157. data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
  158. data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
  159. data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +92 -0
  160. data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
  161. data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
  162. data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
  163. data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
  164. data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
  165. data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
  166. data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
  167. data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
  168. data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
  169. data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
  170. data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
  171. data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
  172. data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
  173. data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
  174. data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
  175. data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
  176. data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
  177. data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
  178. data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
  179. data/ext/libmemcached-0.32/support/Makefile.am +4 -0
  180. data/ext/libmemcached-0.32/support/Makefile.in +485 -0
  181. data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
  182. data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
  183. data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
  184. data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
  185. data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
  186. data/ext/libmemcached-0.32/tests/Makefile.am +105 -0
  187. data/ext/libmemcached-0.32/tests/Makefile.in +748 -0
  188. data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
  189. data/ext/libmemcached-0.32/tests/function.c +4781 -0
  190. data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
  191. data/ext/libmemcached-0.32/tests/output.cmp +7 -0
  192. data/ext/libmemcached-0.32/tests/output.res +7 -0
  193. data/ext/libmemcached-0.32/tests/output2.res +46 -0
  194. data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
  195. data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
  196. data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
  197. data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
  198. data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
  199. data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
  200. data/ext/libmemcached-0.32/tests/server.c +118 -0
  201. data/ext/libmemcached-0.32/tests/server.h +25 -0
  202. data/ext/libmemcached-0.32/tests/start.c +16 -0
  203. data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
  204. data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
  205. data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
  206. data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
  207. data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
  208. data/ext/libmemcached-0.32/tests/test.c +137 -0
  209. data/ext/libmemcached-0.32/tests/test.h +46 -0
  210. data/ext/libmemcached-0.32/tests/udp.c +76 -0
  211. data/memcached.gemspec +4 -4
  212. data/test/unit/memcached_test.rb +30 -0
  213. metadata +213 -16
  214. data/ext/libmemcached-0.32.tar.gz +0 -0
  215. data/ext/libmemcached-1.patch +0 -270
  216. data/ext/libmemcached-10.patch +0 -12
  217. data/ext/libmemcached-2.patch +0 -116
  218. data/ext/libmemcached-3.patch +0 -8
  219. data/ext/libmemcached-4.patch +0 -40
  220. data/ext/libmemcached-5.patch +0 -832
  221. data/ext/libmemcached-6.patch +0 -20
  222. data/ext/libmemcached-7.patch +0 -2989
  223. data/ext/libmemcached-8.patch +0 -137
  224. data/ext/libmemcached-9.patch +0 -13
  225. data/ext/sasl.patch +0 -29283
@@ -0,0 +1,207 @@
1
+ #include "common.h"
2
+
3
+ static memcached_return memcached_auto(memcached_st *ptr,
4
+ const char *verb,
5
+ const char *key, size_t key_length,
6
+ unsigned int offset,
7
+ uint64_t *value)
8
+ {
9
+ size_t send_length;
10
+ memcached_return rc;
11
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
12
+ unsigned int server_key;
13
+ bool no_reply= (ptr->flags & MEM_NOREPLY);
14
+
15
+ unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
16
+ return MEMCACHED_NO_SERVERS;
17
+
18
+ if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
19
+ return MEMCACHED_BAD_KEY_PROVIDED;
20
+
21
+ server_key= memcached_generate_hash(ptr, key, key_length);
22
+
23
+ send_length= (size_t)snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
24
+ "%s %s%.*s %u%s\r\n", verb,
25
+ ptr->prefix_key,
26
+ (int)key_length, key,
27
+ offset, no_reply ? " noreply" : "");
28
+ unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
29
+ return MEMCACHED_WRITE_FAILURE;
30
+
31
+ rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
32
+ if (no_reply || rc != MEMCACHED_SUCCESS)
33
+ return rc;
34
+
35
+ rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
36
+
37
+ /*
38
+ So why recheck responce? Because the protocol is brain dead :)
39
+ The number returned might end up equaling one of the string
40
+ values. Less chance of a mistake with strncmp() so we will
41
+ use it. We still called memcached_response() though since it
42
+ worked its magic for non-blocking IO.
43
+ */
44
+ if (!strncmp(buffer, "ERROR\r\n", 7))
45
+ {
46
+ *value= 0;
47
+ rc= MEMCACHED_PROTOCOL_ERROR;
48
+ }
49
+ else if (!strncmp(buffer, "NOT_FOUND\r\n", 11))
50
+ {
51
+ *value= 0;
52
+ rc= MEMCACHED_NOTFOUND;
53
+ }
54
+ else
55
+ {
56
+ *value= strtoull(buffer, (char **)NULL, 10);
57
+ rc= MEMCACHED_SUCCESS;
58
+ }
59
+
60
+ return rc;
61
+ }
62
+
63
+ static memcached_return binary_incr_decr(memcached_st *ptr, uint8_t cmd,
64
+ const char *key, size_t key_length,
65
+ uint64_t offset, uint64_t initial,
66
+ uint32_t expiration,
67
+ uint64_t *value)
68
+ {
69
+ unsigned int server_key;
70
+ bool no_reply= (ptr->flags & MEM_NOREPLY);
71
+
72
+ unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
73
+ return MEMCACHED_NO_SERVERS;
74
+
75
+ server_key= memcached_generate_hash(ptr, key, key_length);
76
+
77
+ if (no_reply)
78
+ {
79
+ if(cmd == PROTOCOL_BINARY_CMD_DECREMENT)
80
+ cmd= PROTOCOL_BINARY_CMD_DECREMENTQ;
81
+ if(cmd == PROTOCOL_BINARY_CMD_INCREMENT)
82
+ cmd= PROTOCOL_BINARY_CMD_INCREMENTQ;
83
+ }
84
+ protocol_binary_request_incr request= {.bytes= {0}};
85
+
86
+ uint16_t key_with_prefix_length = ptr->prefix_key_length + key_length;
87
+ char *key_with_prefix = alloca(key_with_prefix_length + 1);
88
+ strcpy(key_with_prefix, ptr->prefix_key);
89
+ strcat(key_with_prefix, key);
90
+
91
+
92
+ request.message.header.request.magic= PROTOCOL_BINARY_REQ;
93
+ request.message.header.request.opcode= cmd;
94
+ request.message.header.request.keylen= htons((uint16_t) key_with_prefix_length);
95
+ request.message.header.request.extlen= 20;
96
+ request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
97
+ request.message.header.request.bodylen= htonl((uint32_t) (key_with_prefix_length + request.message.header.request.extlen));
98
+ request.message.body.delta= htonll(offset);
99
+ request.message.body.initial= htonll(initial);
100
+ request.message.body.expiration= htonl((uint32_t) expiration);
101
+
102
+ if ((memcached_do(&ptr->hosts[server_key], request.bytes,
103
+ sizeof(request.bytes), 0)!=MEMCACHED_SUCCESS) ||
104
+ (memcached_io_write(&ptr->hosts[server_key], key_with_prefix, key_with_prefix_length, 1) == -1))
105
+ {
106
+ memcached_io_reset(&ptr->hosts[server_key]);
107
+ return MEMCACHED_WRITE_FAILURE;
108
+ }
109
+
110
+ if (no_reply)
111
+ return MEMCACHED_SUCCESS;
112
+ return memcached_response(&ptr->hosts[server_key], (char*)value, sizeof(*value), NULL);
113
+ }
114
+
115
+ memcached_return memcached_increment(memcached_st *ptr,
116
+ const char *key, size_t key_length,
117
+ uint32_t offset,
118
+ uint64_t *value)
119
+ {
120
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
121
+ unlikely (rc != MEMCACHED_SUCCESS)
122
+ return rc;
123
+
124
+ LIBMEMCACHED_MEMCACHED_INCREMENT_START();
125
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
126
+ rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_INCREMENT, key, key_length,
127
+ (uint64_t)offset, 0, MEMCACHED_EXPIRATION_NOT_ADD,
128
+ value);
129
+ else
130
+ rc= memcached_auto(ptr, "incr", key, key_length, offset, value);
131
+
132
+ LIBMEMCACHED_MEMCACHED_INCREMENT_END();
133
+
134
+ return rc;
135
+ }
136
+
137
+ memcached_return memcached_decrement(memcached_st *ptr,
138
+ const char *key, size_t key_length,
139
+ uint32_t offset,
140
+ uint64_t *value)
141
+ {
142
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
143
+ unlikely (rc != MEMCACHED_SUCCESS)
144
+ return rc;
145
+
146
+ LIBMEMCACHED_MEMCACHED_DECREMENT_START();
147
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
148
+ rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_DECREMENT, key, key_length,
149
+ (uint64_t)offset, 0, MEMCACHED_EXPIRATION_NOT_ADD,
150
+ value);
151
+ else
152
+ rc= memcached_auto(ptr, "decr", key, key_length, offset, value);
153
+
154
+ LIBMEMCACHED_MEMCACHED_DECREMENT_END();
155
+
156
+ return rc;
157
+ }
158
+
159
+ memcached_return memcached_increment_with_initial(memcached_st *ptr,
160
+ const char *key,
161
+ size_t key_length,
162
+ uint64_t offset,
163
+ uint64_t initial,
164
+ time_t expiration,
165
+ uint64_t *value)
166
+ {
167
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
168
+ unlikely (rc != MEMCACHED_SUCCESS)
169
+ return rc;
170
+
171
+ LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START();
172
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
173
+ rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_INCREMENT, key,
174
+ key_length, offset, initial, (uint32_t)expiration,
175
+ value);
176
+ else
177
+ rc= MEMCACHED_PROTOCOL_ERROR;
178
+
179
+ LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_END();
180
+
181
+ return rc;
182
+ }
183
+
184
+ memcached_return memcached_decrement_with_initial(memcached_st *ptr,
185
+ const char *key,
186
+ size_t key_length,
187
+ uint64_t offset,
188
+ uint64_t initial,
189
+ time_t expiration,
190
+ uint64_t *value)
191
+ {
192
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
193
+ unlikely (rc != MEMCACHED_SUCCESS)
194
+ return rc;
195
+
196
+ LIBMEMCACHED_MEMCACHED_DECREMENT_WITH_INITIAL_START();
197
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
198
+ rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_DECREMENT, key,
199
+ key_length, offset, initial, (uint32_t)expiration,
200
+ value);
201
+ else
202
+ rc= MEMCACHED_PROTOCOL_ERROR;
203
+
204
+ LIBMEMCACHED_MEMCACHED_DECREMENT_WITH_INITIAL_END();
205
+
206
+ return rc;
207
+ }
@@ -0,0 +1,285 @@
1
+ #include "common.h"
2
+ #include <time.h>
3
+ #include <sys/types.h>
4
+ #include <sys/socket.h>
5
+ #include <netinet/tcp.h>
6
+
7
+ /*
8
+ This function is used to modify the behavior of running client.
9
+
10
+ We quit all connections so we can reset the sockets.
11
+ */
12
+
13
+ static void set_behavior_flag(memcached_st *ptr, memcached_flags temp_flag, uint64_t data)
14
+ {
15
+ if (data)
16
+ ptr->flags|= temp_flag;
17
+ else
18
+ ptr->flags&= ~temp_flag;
19
+ }
20
+
21
+ memcached_return memcached_behavior_set(memcached_st *ptr,
22
+ memcached_behavior flag,
23
+ uint64_t data)
24
+ {
25
+ switch (flag)
26
+ {
27
+ case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
28
+ ptr->io_msg_watermark= (uint32_t) data;
29
+ break;
30
+ case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
31
+ ptr->io_bytes_watermark= (uint32_t)data;
32
+ break;
33
+ case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH:
34
+ ptr->io_key_prefetch = (uint32_t)data;
35
+ break;
36
+ case MEMCACHED_BEHAVIOR_SND_TIMEOUT:
37
+ ptr->snd_timeout= (int32_t)data;
38
+ break;
39
+ case MEMCACHED_BEHAVIOR_RCV_TIMEOUT:
40
+ ptr->rcv_timeout= (int32_t)data;
41
+ break;
42
+ case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT:
43
+ ptr->server_failure_limit= (uint32_t)data;
44
+ break;
45
+ case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL:
46
+ if (data)
47
+ set_behavior_flag(ptr, MEM_VERIFY_KEY, 0);
48
+ set_behavior_flag(ptr, MEM_BINARY_PROTOCOL, data);
49
+ break;
50
+ case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
51
+ set_behavior_flag(ptr, MEM_SUPPORT_CAS, data);
52
+ break;
53
+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
54
+ set_behavior_flag(ptr, MEM_NO_BLOCK, data);
55
+ memcached_quit(ptr);
56
+ break;
57
+ case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
58
+ set_behavior_flag(ptr, MEM_BUFFER_REQUESTS, data);
59
+ memcached_quit(ptr);
60
+ break;
61
+ case MEMCACHED_BEHAVIOR_USE_UDP:
62
+ if (ptr->number_of_hosts)
63
+ return MEMCACHED_FAILURE;
64
+ set_behavior_flag(ptr, MEM_USE_UDP, data);
65
+ if (data)
66
+ set_behavior_flag(ptr,MEM_NOREPLY,data);
67
+ break;
68
+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
69
+ set_behavior_flag(ptr, MEM_TCP_NODELAY, data);
70
+ memcached_quit(ptr);
71
+ break;
72
+ case MEMCACHED_BEHAVIOR_DISTRIBUTION:
73
+ {
74
+ ptr->distribution= (memcached_server_distribution)(data);
75
+ if (ptr->distribution == MEMCACHED_DISTRIBUTION_RANDOM)
76
+ {
77
+ srandom((uint32_t) time(NULL));
78
+ }
79
+ run_distribution(ptr);
80
+ break;
81
+ }
82
+ case MEMCACHED_BEHAVIOR_KETAMA:
83
+ {
84
+ if (data)
85
+ {
86
+ ptr->hash= MEMCACHED_HASH_MD5;
87
+ ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA;
88
+ }
89
+ else
90
+ {
91
+ ptr->hash= 0;
92
+ ptr->distribution= 0;
93
+ }
94
+ run_distribution(ptr);
95
+ break;
96
+ }
97
+ case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
98
+ {
99
+ ptr->hash= MEMCACHED_HASH_MD5;
100
+ ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA;
101
+ set_behavior_flag(ptr, MEM_KETAMA_WEIGHTED, data);
102
+ run_distribution(ptr);
103
+ break;
104
+ }
105
+ case MEMCACHED_BEHAVIOR_HASH:
106
+ #ifndef HAVE_HSIEH_HASH
107
+ if ((memcached_hash)(data) == MEMCACHED_HASH_HSIEH)
108
+ return MEMCACHED_FAILURE;
109
+ #endif
110
+ ptr->hash= (memcached_hash)(data);
111
+ break;
112
+ case MEMCACHED_BEHAVIOR_KETAMA_HASH:
113
+ ptr->hash_continuum= (memcached_hash)(data);
114
+ run_distribution(ptr);
115
+ break;
116
+ case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
117
+ set_behavior_flag(ptr, MEM_USE_CACHE_LOOKUPS, data);
118
+ memcached_quit(ptr);
119
+ break;
120
+ case MEMCACHED_BEHAVIOR_VERIFY_KEY:
121
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
122
+ break;
123
+ set_behavior_flag(ptr, MEM_VERIFY_KEY, data);
124
+ break;
125
+ case MEMCACHED_BEHAVIOR_SORT_HOSTS:
126
+ {
127
+ set_behavior_flag(ptr, MEM_USE_SORT_HOSTS, data);
128
+ run_distribution(ptr);
129
+
130
+ break;
131
+ }
132
+ case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
133
+ ptr->poll_timeout= (int32_t)data;
134
+ break;
135
+ case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
136
+ ptr->connect_timeout= (int32_t)data;
137
+ break;
138
+ case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
139
+ ptr->retry_timeout= (int32_t)data;
140
+ break;
141
+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
142
+ ptr->send_size= (int32_t)data;
143
+ memcached_quit(ptr);
144
+ break;
145
+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
146
+ ptr->recv_size= (int32_t)data;
147
+ memcached_quit(ptr);
148
+ break;
149
+ case MEMCACHED_BEHAVIOR_USER_DATA:
150
+ return MEMCACHED_FAILURE;
151
+ case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY:
152
+ set_behavior_flag(ptr, MEM_HASH_WITH_PREFIX_KEY, data);
153
+ break;
154
+ case MEMCACHED_BEHAVIOR_NOREPLY:
155
+ set_behavior_flag(ptr, MEM_NOREPLY, data);
156
+ break;
157
+ case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS:
158
+ set_behavior_flag(ptr, MEM_AUTO_EJECT_HOSTS, data);
159
+ break;
160
+ default:
161
+ /* Shouldn't get here */
162
+ WATCHPOINT_ASSERT(flag);
163
+ break;
164
+ }
165
+
166
+ return MEMCACHED_SUCCESS;
167
+ }
168
+
169
+ uint64_t memcached_behavior_get(memcached_st *ptr,
170
+ memcached_behavior flag)
171
+ {
172
+ memcached_flags temp_flag= MEM_NO_BLOCK;
173
+
174
+ switch (flag)
175
+ {
176
+ case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
177
+ return ptr->io_msg_watermark;
178
+ case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
179
+ return ptr->io_bytes_watermark;
180
+ case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH:
181
+ return ptr->io_key_prefetch;
182
+ case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL:
183
+ temp_flag= MEM_BINARY_PROTOCOL;
184
+ break;
185
+ case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
186
+ temp_flag= MEM_SUPPORT_CAS;
187
+ break;
188
+ case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
189
+ temp_flag= MEM_USE_CACHE_LOOKUPS;
190
+ break;
191
+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
192
+ temp_flag= MEM_NO_BLOCK;
193
+ break;
194
+ case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
195
+ temp_flag= MEM_BUFFER_REQUESTS;
196
+ break;
197
+ case MEMCACHED_BEHAVIOR_USE_UDP:
198
+ temp_flag= MEM_USE_UDP;
199
+ break;
200
+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
201
+ temp_flag= MEM_TCP_NODELAY;
202
+ break;
203
+ case MEMCACHED_BEHAVIOR_VERIFY_KEY:
204
+ temp_flag= MEM_VERIFY_KEY;
205
+ break;
206
+ case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
207
+ temp_flag= MEM_KETAMA_WEIGHTED;
208
+ break;
209
+ case MEMCACHED_BEHAVIOR_DISTRIBUTION:
210
+ return ptr->distribution;
211
+ case MEMCACHED_BEHAVIOR_KETAMA:
212
+ return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0;
213
+ case MEMCACHED_BEHAVIOR_HASH:
214
+ return ptr->hash;
215
+ case MEMCACHED_BEHAVIOR_KETAMA_HASH:
216
+ return ptr->hash_continuum;
217
+ case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT:
218
+ return ptr->server_failure_limit;
219
+ case MEMCACHED_BEHAVIOR_SORT_HOSTS:
220
+ temp_flag= MEM_USE_SORT_HOSTS;
221
+ break;
222
+ case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
223
+ return (uint64_t)ptr->poll_timeout;
224
+ case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
225
+ return (uint64_t)ptr->connect_timeout;
226
+ case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
227
+ return (uint64_t)ptr->retry_timeout;
228
+ case MEMCACHED_BEHAVIOR_SND_TIMEOUT:
229
+ return (uint64_t)ptr->snd_timeout;
230
+ case MEMCACHED_BEHAVIOR_RCV_TIMEOUT:
231
+ return (uint64_t)ptr->rcv_timeout;
232
+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
233
+ {
234
+ int sock_size;
235
+ socklen_t sock_length= sizeof(int);
236
+
237
+ /* REFACTOR */
238
+ /* We just try the first host, and if it is down we return zero */
239
+ if ((memcached_connect(&ptr->hosts[0])) != MEMCACHED_SUCCESS)
240
+ return 0;
241
+
242
+ if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
243
+ SO_SNDBUF, &sock_size, &sock_length))
244
+ return 0; /* Zero means error */
245
+
246
+ return (uint64_t) sock_size;
247
+ }
248
+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
249
+ {
250
+ int sock_size;
251
+ socklen_t sock_length= sizeof(int);
252
+
253
+ /* REFACTOR */
254
+ /* We just try the first host, and if it is down we return zero */
255
+ if ((memcached_connect(&ptr->hosts[0])) != MEMCACHED_SUCCESS)
256
+ return 0;
257
+
258
+ if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
259
+ SO_RCVBUF, &sock_size, &sock_length))
260
+ return 0; /* Zero means error */
261
+
262
+ return (uint64_t) sock_size;
263
+ }
264
+ case MEMCACHED_BEHAVIOR_USER_DATA:
265
+ return MEMCACHED_FAILURE;
266
+ case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY:
267
+ temp_flag= MEM_HASH_WITH_PREFIX_KEY;
268
+ break;
269
+ case MEMCACHED_BEHAVIOR_NOREPLY:
270
+ temp_flag= MEM_NOREPLY;
271
+ break;
272
+ case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS:
273
+ temp_flag= MEM_AUTO_EJECT_HOSTS;
274
+ break;
275
+ default:
276
+ WATCHPOINT_ASSERT(flag);
277
+ break;
278
+ }
279
+
280
+ WATCHPOINT_ASSERT(temp_flag); /* Programming mistake if it gets this far */
281
+ if (ptr->flags & temp_flag)
282
+ return 1;
283
+ else
284
+ return 0;
285
+ }