1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
From fd6795035e4bcd1d2606f4f8f69c104bfbf5d5ff Mon Sep 17 00:00:00 2001
From: Charles Ellis <hamled@gmail.com>
Date: Sun, 20 May 2012 23:20:33 -0700
Subject: [PATCH] Memcached stats method compatiblity fix
The stats method of Memcached is now compatible with libmemcached 1.0+.
---
addons/Memcached/source/IoMemcached.c | 41 +++++++++++++++++++++--------------
modules/FindLibMemcached.cmake | 2 +-
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/addons/Memcached/source/IoMemcached.c b/addons/Memcached/source/IoMemcached.c
index c1be9ff..aa3fe67 100644
--- addons/Memcached/source/IoMemcached.c
+++ addons/Memcached/source/IoMemcached.c
@@ -472,39 +472,48 @@ values are maps with actual stats.
IoObject *IoMemcached_stats(IoMemcached *self, IoObject *locals, IoMessage *m)
{
IoMap *results_map = IoMap_new(IOSTATE);
+ memcached_st *mc = DATA(self)->mc;
- int i;
- for(i = 0; i < memcached_server_list_count(DATA(self)->mc->servers); i++) {
- memcached_server_st *server = DATA(self)->mc->servers + i;
+ uint32_t pos = 0;
+ while(pos < memcached_server_count(mc)) {
+ memcached_server_instance_st server = memcached_server_instance_by_position(mc, pos);
+ if(server == NULL)
+ continue;
+
+ const char *hostname = memcached_server_name(server);
+ const in_port_t port = memcached_server_port(server);
memcached_stat_st stats;
- if(memcached_stat_servername(&stats, "", server->hostname, server->port) != 0)
+ memcached_return_t rc = memcached_stat_servername(&stats, "", hostname, port);
+ if(rc != MEMCACHED_SUCCESS)
continue;
- memcached_return rc;
- char **ckeys = memcached_stat_get_keys(DATA(self)->mc, &stats, &rc);
-
- int ckeys_count = 0;
- while(ckeys[ckeys_count] != NULL)
- ckeys_count++;
+ char **ckeys = memcached_stat_get_keys(mc, &stats, &rc);
+ if(rc != MEMCACHED_SUCCESS)
+ continue;
IoMap *per_server_map = IoMap_new(IOSTATE);
- int k;
- for(k = 0; k < ckeys_count; k++) {
- char *ckey = ckeys[k];
- char *cvalue = memcached_stat_get_value(DATA(self)->mc, &stats, ckey, &rc);
+ char *ckey = *ckeys;
+ while(ckey != NULL) {
+ char *cvalue = memcached_stat_get_value(mc, &stats, ckey, &rc);
+ if(rc != MEMCACHED_SUCCESS)
+ continue;
+
IoMap_rawAtPut(per_server_map, IOSYMBOL(ckey), IOSYMBOL(cvalue));
free(cvalue);
+ ckey++;
}
free(ckeys);
// "127.0.0.1:11211"
- char *server_key = (char *) malloc((strlen(server->hostname) + 1 + 5 + 1) * sizeof(char));
- sprintf(server_key, "%s:%d", server->hostname, server->port);
+ char *server_key = (char *) malloc((strlen(hostname) + 1 + 5 + 1) * sizeof(char));
+ sprintf(server_key, "%s:%d", hostname, port);
IoMap_rawAtPut(results_map, IOSYMBOL(server_key), per_server_map);
free(server_key);
+
+ pos++;
}
return results_map;
diff --git a/modules/FindLibMemcached.cmake b/modules/FindLibMemcached.cmake
index 46bf5e5..07ee3bb 100644
--- modules/FindLibMemcached.cmake
+++ modules/FindLibMemcached.cmake
@@ -6,7 +6,7 @@
FIND_PATH(LIBMEMCACHED_INCLUDE_DIR libmemcached/memcached.h)
-FIND_LIBRARY(LIBMEMCACHED_LIBRARY NAMES memcached PATH /usr/lib /usr/local/lib)
+FIND_LIBRARY(LIBMEMCACHED_LIBRARY NAMES memcached libmemcached PATH /usr/lib /usr/local/lib)
IF(LIBMEMCACHED_INCLUDE_DIR AND LIBMEMCACHED_LIBRARY)
SET(LIBMEMCACHED_FOUND 1)
|