memcached 1.2.6 → 1.2.7

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.
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,93 @@
1
+ /*
2
+ * Summary: String structure used for libmemcached.
3
+ *
4
+ * Copy: See Copyright for the status of this software.
5
+ *
6
+ * Author: Brian Aker
7
+ */
8
+
9
+ #ifndef __MEMCACHED_SERVER_H__
10
+ #define __MEMCACHED_SERVER_H__
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ struct memcached_server_st {
17
+ bool is_allocated;
18
+ bool sockaddr_inited;
19
+ uint16_t count;
20
+ unsigned int cursor_active;
21
+ unsigned int port;
22
+ int cached_errno;
23
+ int fd;
24
+ uint32_t io_bytes_sent; /* # bytes sent since last read */
25
+ uint32_t server_failure_counter;
26
+ uint32_t weight;
27
+ uint8_t major_version;
28
+ uint8_t micro_version;
29
+ uint8_t minor_version;
30
+ memcached_connection type;
31
+ char *read_ptr;
32
+ char *cached_server_error;
33
+ size_t read_buffer_length;
34
+ size_t read_data_length;
35
+ size_t write_buffer_offset;
36
+ struct addrinfo *address_info;
37
+ time_t next_retry;
38
+ memcached_st *root;
39
+ uint64_t limit_maxbytes;
40
+ char read_buffer[MEMCACHED_MAX_BUFFER];
41
+ char write_buffer[MEMCACHED_MAX_BUFFER];
42
+ char hostname[MEMCACHED_MAX_HOST_LENGTH];
43
+ };
44
+
45
+ #define memcached_server_count(A) (A)->number_of_hosts
46
+ #define memcached_server_name(A,B) (B).hostname
47
+ #define memcached_server_port(A,B) (B).port
48
+ #define memcached_server_list(A) (A)->hosts
49
+ #define memcached_server_response_count(A) (A)->cursor_active
50
+
51
+ LIBMEMCACHED_API
52
+ memcached_return memcached_server_cursor(memcached_st *ptr,
53
+ memcached_server_function *callback,
54
+ void *context,
55
+ unsigned int number_of_callbacks);
56
+
57
+ LIBMEMCACHED_API
58
+ memcached_server_st *memcached_server_by_key(memcached_st *ptr, const char *key,
59
+ size_t key_length, memcached_return *error);
60
+
61
+ LIBMEMCACHED_API
62
+ const char *memcached_server_error(memcached_server_st *ptr);
63
+
64
+ LIBMEMCACHED_API
65
+ void memcached_server_error_reset(memcached_server_st *ptr);
66
+
67
+ /* These should not currently be used by end users */
68
+ /* TODO: Is the above comment valid? If so, how can we unit test these if they
69
+ * aren't exported. If not, we should remove the comment */
70
+ LIBMEMCACHED_API
71
+ memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr);
72
+
73
+ LIBMEMCACHED_API
74
+ memcached_server_st *memcached_server_create_with(memcached_st *memc, memcached_server_st *host,
75
+ const char *hostname, unsigned int port,
76
+ uint32_t weight, memcached_connection type);
77
+
78
+ LIBMEMCACHED_API
79
+ void memcached_server_free(memcached_server_st *ptr);
80
+ LIBMEMCACHED_API
81
+ memcached_server_st *memcached_server_clone(memcached_server_st *clone, memcached_server_st *ptr);
82
+ LIBMEMCACHED_API
83
+ memcached_analysis_st *memcached_analyze(memcached_st *memc, memcached_stat_st *memc_stat,
84
+ memcached_return *error);
85
+
86
+ LIBMEMCACHED_API
87
+ memcached_return memcached_server_remove(memcached_server_st *st_ptr);
88
+
89
+ #ifdef __cplusplus
90
+ }
91
+ #endif
92
+
93
+ #endif /* __MEMCACHED_SERVER_H__ */
@@ -0,0 +1,454 @@
1
+ /*
2
+ */
3
+
4
+ #include "common.h"
5
+
6
+ static const char *memcached_stat_keys[] = {
7
+ "pid",
8
+ "uptime",
9
+ "time",
10
+ "version",
11
+ "pointer_size",
12
+ "rusage_user",
13
+ "rusage_system",
14
+ "curr_items",
15
+ "total_items",
16
+ "bytes",
17
+ "curr_connections",
18
+ "total_connections",
19
+ "connection_structures",
20
+ "cmd_get",
21
+ "cmd_set",
22
+ "get_hits",
23
+ "get_misses",
24
+ "evictions",
25
+ "bytes_read",
26
+ "bytes_written",
27
+ "limit_maxbytes",
28
+ "threads",
29
+ NULL
30
+ };
31
+
32
+
33
+ static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char *value)
34
+ {
35
+
36
+ if(strlen(key) < 1)
37
+ {
38
+ WATCHPOINT_STRING(key);
39
+ return MEMCACHED_UNKNOWN_STAT_KEY;
40
+ }
41
+ else if (!strcmp("pid", key))
42
+ {
43
+ memc_stat->pid= (uint32_t) strtol(value, (char **)NULL, 10);
44
+ }
45
+ else if (!strcmp("uptime", key))
46
+ {
47
+ memc_stat->uptime= (uint32_t) strtol(value, (char **)NULL, 10);
48
+ }
49
+ else if (!strcmp("time", key))
50
+ {
51
+ memc_stat->time= (uint32_t) strtol(value, (char **)NULL, 10);
52
+ }
53
+ else if (!strcmp("version", key))
54
+ {
55
+ memcpy(memc_stat->version, value, strlen(value));
56
+ memc_stat->version[strlen(value)]= 0;
57
+ }
58
+ else if (!strcmp("pointer_size", key))
59
+ {
60
+ memc_stat->pointer_size= (uint32_t) strtol(value, (char **)NULL, 10);
61
+ }
62
+ else if (!strcmp("rusage_user", key))
63
+ {
64
+ char *walk_ptr;
65
+ for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++);
66
+ *walk_ptr= 0;
67
+ walk_ptr++;
68
+ memc_stat->rusage_user_seconds= (uint32_t) strtol(value, (char **)NULL, 10);
69
+ memc_stat->rusage_user_microseconds= (uint32_t) strtol(walk_ptr, (char **)NULL, 10);
70
+ }
71
+ else if (!strcmp("rusage_system", key))
72
+ {
73
+ char *walk_ptr;
74
+ for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++);
75
+ *walk_ptr= 0;
76
+ walk_ptr++;
77
+ memc_stat->rusage_system_seconds= (uint32_t) strtol(value, (char **)NULL, 10);
78
+ memc_stat->rusage_system_microseconds= (uint32_t) strtol(walk_ptr, (char **)NULL, 10);
79
+ }
80
+ else if (!strcmp("curr_items", key))
81
+ {
82
+ memc_stat->curr_items= (uint32_t) strtol(value, (char **)NULL, 10);
83
+ }
84
+ else if (!strcmp("total_items", key))
85
+ {
86
+ memc_stat->total_items= (uint32_t) strtol(value, (char **)NULL, 10);
87
+ }
88
+ else if (!strcmp("bytes_read", key))
89
+ {
90
+ memc_stat->bytes_read= (uint32_t) strtoll(value, (char **)NULL, 10);
91
+ }
92
+ else if (!strcmp("bytes_written", key))
93
+ {
94
+ memc_stat->bytes_written= (uint32_t) strtoll(value, (char **)NULL, 10);
95
+ }
96
+ else if (!strcmp("bytes", key))
97
+ {
98
+ memc_stat->bytes= (uint32_t) strtoll(value, (char **)NULL, 10);
99
+ }
100
+ else if (!strcmp("curr_connections", key))
101
+ {
102
+ memc_stat->curr_connections= (uint32_t) strtoll(value, (char **)NULL, 10);
103
+ }
104
+ else if (!strcmp("total_connections", key))
105
+ {
106
+ memc_stat->total_connections= (uint32_t) strtoll(value, (char **)NULL, 10);
107
+ }
108
+ else if (!strcmp("connection_structures", key))
109
+ {
110
+ memc_stat->connection_structures= (uint32_t) strtol(value, (char **)NULL, 10);
111
+ }
112
+ else if (!strcmp("cmd_get", key))
113
+ {
114
+ memc_stat->cmd_get= (uint64_t) strtoll(value, (char **)NULL, 10);
115
+ }
116
+ else if (!strcmp("cmd_set", key))
117
+ {
118
+ memc_stat->cmd_set= (uint64_t) strtoll(value, (char **)NULL, 10);
119
+ }
120
+ else if (!strcmp("get_hits", key))
121
+ {
122
+ memc_stat->get_hits= (uint64_t) strtoll(value, (char **)NULL, 10);
123
+ }
124
+ else if (!strcmp("get_misses", key))
125
+ {
126
+ memc_stat->get_misses= (uint64_t)strtoll(value, (char **)NULL, 10);
127
+ }
128
+ else if (!strcmp("evictions", key))
129
+ {
130
+ memc_stat->evictions= (uint64_t)strtoll(value, (char **)NULL, 10);
131
+ }
132
+ else if (!strcmp("limit_maxbytes", key))
133
+ {
134
+ memc_stat->limit_maxbytes= (uint64_t) strtoll(value, (char **)NULL, 10);
135
+ }
136
+ else if (!strcmp("threads", key))
137
+ {
138
+ memc_stat->threads= (uint32_t) strtol(value, (char **)NULL, 10);
139
+ }
140
+ else if (!(strcmp("delete_misses", key) == 0 ||/* New stats in the 1.3 beta */
141
+ strcmp("delete_hits", key) == 0 ||/* Just swallow them for now.. */
142
+ strcmp("incr_misses", key) == 0 ||
143
+ strcmp("incr_hits", key) == 0 ||
144
+ strcmp("decr_misses", key) == 0 ||
145
+ strcmp("decr_hits", key) == 0 ||
146
+ strcmp("cas_misses", key) == 0 ||
147
+ strcmp("cas_hits", key) == 0 ||
148
+ strcmp("cas_badval", key) == 0 ||
149
+ strcmp("cmd_flush", key) == 0 ||
150
+ strcmp("accepting_conns", key) == 0 ||
151
+ strcmp("listen_disabled_num", key) == 0 ||
152
+ strcmp("conn_yields", key) == 0))
153
+ {
154
+ WATCHPOINT_STRING(key);
155
+ return MEMCACHED_UNKNOWN_STAT_KEY;
156
+ }
157
+
158
+ return MEMCACHED_SUCCESS;
159
+ }
160
+
161
+ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
162
+ const char *key, memcached_return *error)
163
+ {
164
+ char buffer[SMALL_STRING_LEN];
165
+ int length;
166
+ char *ret;
167
+
168
+ *error= MEMCACHED_SUCCESS;
169
+
170
+ if (!memcmp("pid", key, strlen("pid")))
171
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->pid);
172
+ else if (!memcmp("uptime", key, strlen("uptime")))
173
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->uptime);
174
+ else if (!memcmp("time", key, strlen("time")))
175
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->time);
176
+ else if (!memcmp("version", key, strlen("version")))
177
+ length= snprintf(buffer, SMALL_STRING_LEN,"%s", memc_stat->version);
178
+ else if (!memcmp("pointer_size", key, strlen("pointer_size")))
179
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->pointer_size);
180
+ else if (!memcmp("rusage_user", key, strlen("rusage_user")))
181
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", memc_stat->rusage_user_seconds, memc_stat->rusage_user_microseconds);
182
+ else if (!memcmp("rusage_system", key, strlen("rusage_system")))
183
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", memc_stat->rusage_system_seconds, memc_stat->rusage_system_microseconds);
184
+ else if (!memcmp("curr_items", key, strlen("curr_items")))
185
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_items);
186
+ else if (!memcmp("total_items", key, strlen("total_items")))
187
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_items);
188
+ else if (!memcmp("bytes", key, strlen("bytes")))
189
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes);
190
+ else if (!memcmp("curr_connections", key, strlen("curr_connections")))
191
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_connections);
192
+ else if (!memcmp("total_connections", key, strlen("total_connections")))
193
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_connections);
194
+ else if (!memcmp("connection_structures", key, strlen("connection_structures")))
195
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->connection_structures);
196
+ else if (!memcmp("cmd_get", key, strlen("cmd_get")))
197
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->cmd_get);
198
+ else if (!memcmp("cmd_set", key, strlen("cmd_set")))
199
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->cmd_set);
200
+ else if (!memcmp("get_hits", key, strlen("get_hits")))
201
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->get_hits);
202
+ else if (!memcmp("get_misses", key, strlen("get_misses")))
203
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->get_misses);
204
+ else if (!memcmp("evictions", key, strlen("evictions")))
205
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->evictions);
206
+ else if (!memcmp("bytes_read", key, strlen("bytes_read")))
207
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_read);
208
+ else if (!memcmp("bytes_written", key, strlen("bytes_written")))
209
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_written);
210
+ else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes")))
211
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->limit_maxbytes);
212
+ else if (!memcmp("threads", key, strlen("threads")))
213
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->threads);
214
+ else
215
+ {
216
+ *error= MEMCACHED_NOTFOUND;
217
+ return NULL;
218
+ }
219
+
220
+ ret= ptr->call_malloc(ptr, (size_t) (length + 1));
221
+ memcpy(ret, buffer, (size_t) length);
222
+ ret[length]= '\0';
223
+
224
+ return ret;
225
+ }
226
+
227
+ static memcached_return binary_stats_fetch(memcached_st *ptr,
228
+ memcached_stat_st *memc_stat,
229
+ char *args,
230
+ unsigned int server_key)
231
+ {
232
+ memcached_return rc;
233
+
234
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
235
+ protocol_binary_request_stats request= {.bytes= {0}};
236
+ request.message.header.request.magic= PROTOCOL_BINARY_REQ;
237
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT;
238
+ request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
239
+
240
+ if (args != NULL)
241
+ {
242
+ size_t len= strlen(args);
243
+
244
+ rc= memcached_validate_key_length(len, true);
245
+ unlikely (rc != MEMCACHED_SUCCESS)
246
+ return rc;
247
+
248
+ request.message.header.request.keylen= htons((uint16_t)len);
249
+ request.message.header.request.bodylen= htonl((uint32_t) len);
250
+
251
+ if ((memcached_do(&ptr->hosts[server_key], request.bytes,
252
+ sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) ||
253
+ (memcached_io_write(&ptr->hosts[server_key], args, len, 1) == -1))
254
+ {
255
+ memcached_io_reset(&ptr->hosts[server_key]);
256
+ return MEMCACHED_WRITE_FAILURE;
257
+ }
258
+ }
259
+ else
260
+ {
261
+ if (memcached_do(&ptr->hosts[server_key], request.bytes,
262
+ sizeof(request.bytes), 1) != MEMCACHED_SUCCESS)
263
+ {
264
+ memcached_io_reset(&ptr->hosts[server_key]);
265
+ return MEMCACHED_WRITE_FAILURE;
266
+ }
267
+ }
268
+
269
+ memcached_server_response_decrement(&ptr->hosts[server_key]);
270
+ do
271
+ {
272
+ rc= memcached_response(&ptr->hosts[server_key], buffer,
273
+ sizeof(buffer), NULL);
274
+ if (rc == MEMCACHED_END)
275
+ break;
276
+
277
+ unlikely (rc != MEMCACHED_SUCCESS)
278
+ {
279
+ memcached_io_reset(&ptr->hosts[server_key]);
280
+ return rc;
281
+ }
282
+
283
+ unlikely((set_data(memc_stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY)
284
+ {
285
+ WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
286
+ WATCHPOINT_ASSERT(0);
287
+ }
288
+ } while (1);
289
+
290
+ /* shit... memcached_response will decrement the counter, so I need to
291
+ ** reset it.. todo: look at this and try to find a better solution.
292
+ */
293
+ ptr->hosts[server_key].cursor_active= 0;
294
+
295
+ return MEMCACHED_SUCCESS;
296
+ }
297
+
298
+ static memcached_return ascii_stats_fetch(memcached_st *ptr,
299
+ memcached_stat_st *memc_stat,
300
+ char *args,
301
+ unsigned int server_key)
302
+ {
303
+ memcached_return rc;
304
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
305
+ size_t send_length;
306
+
307
+ if (args)
308
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
309
+ "stats %s\r\n", args);
310
+ else
311
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
312
+ "stats\r\n");
313
+
314
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
315
+ return MEMCACHED_WRITE_FAILURE;
316
+
317
+ rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
318
+ if (rc != MEMCACHED_SUCCESS)
319
+ goto error;
320
+
321
+ while (1)
322
+ {
323
+ rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
324
+
325
+ if (rc == MEMCACHED_STAT)
326
+ {
327
+ char *string_ptr, *end_ptr;
328
+ char *key, *value;
329
+
330
+ string_ptr= buffer;
331
+ string_ptr+= 5; /* Move past STAT */
332
+ for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++);
333
+ key= string_ptr;
334
+ key[(size_t)(end_ptr-string_ptr)]= 0;
335
+
336
+ string_ptr= end_ptr + 1;
337
+ for (end_ptr= string_ptr; !(isspace(*end_ptr)); end_ptr++);
338
+ value= string_ptr;
339
+ value[(size_t)(end_ptr-string_ptr)]= 0;
340
+ string_ptr= end_ptr + 2;
341
+ unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY)
342
+ {
343
+ WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
344
+ WATCHPOINT_ASSERT(0);
345
+ }
346
+ }
347
+ else
348
+ break;
349
+ }
350
+
351
+ error:
352
+ if (rc == MEMCACHED_END)
353
+ return MEMCACHED_SUCCESS;
354
+ else
355
+ return rc;
356
+ }
357
+
358
+ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error)
359
+ {
360
+ unsigned int x;
361
+ memcached_return rc;
362
+ memcached_stat_st *stats;
363
+
364
+ unlikely (ptr->flags & MEM_USE_UDP)
365
+ {
366
+ *error= MEMCACHED_NOT_SUPPORTED;
367
+ return NULL;
368
+ }
369
+
370
+ stats= ptr->call_calloc(ptr, ptr->number_of_hosts, sizeof(memcached_stat_st));
371
+
372
+ if (!stats)
373
+ {
374
+ *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
375
+ return NULL;
376
+ }
377
+
378
+ rc= MEMCACHED_SUCCESS;
379
+ for (x= 0; x < ptr->number_of_hosts; x++)
380
+ {
381
+ memcached_return temp_return;
382
+
383
+ if (ptr->flags & MEM_BINARY_PROTOCOL)
384
+ temp_return= binary_stats_fetch(ptr, stats + x, args, x);
385
+ else
386
+ temp_return= ascii_stats_fetch(ptr, stats + x, args, x);
387
+
388
+ if (temp_return != MEMCACHED_SUCCESS)
389
+ rc= MEMCACHED_SOME_ERRORS;
390
+ }
391
+
392
+ *error= rc;
393
+ return stats;
394
+ }
395
+
396
+ memcached_return memcached_stat_servername(memcached_stat_st *memc_stat, char *args,
397
+ char *hostname, unsigned int port)
398
+ {
399
+ memcached_return rc;
400
+ memcached_st memc;
401
+
402
+ memcached_create(&memc);
403
+
404
+ memcached_server_add(&memc, hostname, port);
405
+
406
+ if (memc.flags & MEM_BINARY_PROTOCOL)
407
+ rc= binary_stats_fetch(&memc, memc_stat, args, 0);
408
+ else
409
+ rc= ascii_stats_fetch(&memc, memc_stat, args, 0);
410
+
411
+ memcached_free(&memc);
412
+
413
+ return rc;
414
+ }
415
+
416
+ /*
417
+ We make a copy of the keys since at some point in the not so distant future
418
+ we will add support for "found" keys.
419
+ */
420
+ char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat,
421
+ memcached_return *error)
422
+ {
423
+ (void) memc_stat;
424
+ char **list;
425
+ size_t length= sizeof(memcached_stat_keys);
426
+
427
+ list= ptr->call_malloc(ptr, length);
428
+
429
+ if (!list)
430
+ {
431
+ *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
432
+ return NULL;
433
+ }
434
+
435
+ memcpy(list, memcached_stat_keys, sizeof(memcached_stat_keys));
436
+
437
+ *error= MEMCACHED_SUCCESS;
438
+
439
+ return list;
440
+ }
441
+
442
+ void memcached_stat_free(memcached_st *ptr, memcached_stat_st *memc_stat)
443
+ {
444
+ if (memc_stat == NULL)
445
+ {
446
+ WATCHPOINT_ASSERT(0); /* Be polite, but when debugging catch this as an error */
447
+ return;
448
+ }
449
+
450
+ if (ptr)
451
+ ptr->call_free(ptr, memc_stat);
452
+ else
453
+ free(memc_stat);
454
+ }