[asterisk-commits] snuffy: branch snuffy/func_memcache r229910 - in /team/snuffy/func_memcache: ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Nov 13 06:09:11 CST 2009
Author: snuffy
Date: Fri Nov 13 06:09:08 2009
New Revision: 229910
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=229910
Log:
Adjust per oej comments, add note about makefile link hack
Modified:
team/snuffy/func_memcache/Makefile
team/snuffy/func_memcache/funcs/func_memcache.c
Modified: team/snuffy/func_memcache/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/snuffy/func_memcache/Makefile?view=diff&rev=229910&r1=229909&r2=229910
==============================================================================
--- team/snuffy/func_memcache/Makefile (original)
+++ team/snuffy/func_memcache/Makefile Fri Nov 13 06:09:08 2009
@@ -106,6 +106,8 @@
# overrides
_ASTCFLAGS+=$(COPTS)
_ASTLDFLAGS+=$(LDOPTS)
+# This SHOULD NOT BE HERE, NEED AUTOCONF DODGEY HACK
+_ASTLDFLAGS+=-lmemcached
# libxml2 cflags
_ASTCFLAGS+=$(LIBXML2_INCLUDE)
Modified: team/snuffy/func_memcache/funcs/func_memcache.c
URL: http://svnview.digium.com/svn/asterisk/team/snuffy/func_memcache/funcs/func_memcache.c?view=diff&rev=229910&r1=229909&r2=229910
==============================================================================
--- team/snuffy/func_memcache/funcs/func_memcache.c (original)
+++ team/snuffy/func_memcache/funcs/func_memcache.c Fri Nov 13 06:09:08 2009
@@ -172,8 +172,7 @@
if (!strcmp(memc->name, server)) {
value = memcached_get(memc->conn, key, k_len, &ss, &flags, &memc->rc);
ast_log(LOG_WARNING,"errno:%d\tstr:%s\n", memc->rc,
- memcached_strerror(memc->conn, memc->rc));
- //ast_log(LOG_WARNING, "key:%s ks:%d ksz:%d\n", key, strlen(key), sizeof(key));
+ memcached_strerror(memc->conn, memc->rc));
}
}
@@ -181,12 +180,12 @@
if(value) {
ast_copy_string(buf, value, len);
- //Free memory from libmemcached library
ast_free(value);
}
return 0;
}
+
static int fn_memcache_put(const char *key, const char *server, const char *expiry, const char *value)
{
struct memcache_con *memc;
@@ -197,9 +196,13 @@
if (expiry) {
long seconds;
seconds = atol(expiry);
- memc->rc = memcached_set(memc->conn, key, strlen(key), value, sizeof(value), (time_t)seconds, (uint32_t)0);
+ memc->rc = memcached_set(memc->conn, key, strlen(key),
+ value, sizeof(value), (time_t)seconds,
+ (uint32_t)0);
} else {
- memc->rc = memcached_set(memc->conn, key, strlen(key), value, sizeof(value), (time_t)0, (uint32_t)0);
+ memc->rc = memcached_set(memc->conn, key, strlen(key),
+ value, sizeof(value), (time_t)0,
+ (uint32_t)0);
}
ast_log(LOG_WARNING,"errno:%d\tstr:%s\n", memc->rc, memcached_strerror(memc->conn,memc->rc));
}
@@ -215,19 +218,19 @@
AST_RWLIST_RDLOCK(&memcaches);
AST_RWLIST_TRAVERSE(&memcaches, memc, list) {
- if (!strcmp(memc->name, server)) {
- if (expiry) {
- long seconds;
- seconds = atol(expiry);
- memc->rc = memcached_delete(memc->conn, key, strlen(key),
- (time_t)seconds);
- } else {
- memc->rc = memcached_delete(memc->conn, key, strlen(key),
- (time_t)0);
- }
- ast_log(LOG_WARNING,"errno:%d\tstr:%s\n", memc->rc,
- memcached_strerror(memc->conn,memc->rc));
- }
+ if (!strcmp(memc->name, server)) {
+ if (expiry) {
+ long seconds;
+ seconds = atol(expiry);
+ memc->rc = memcached_delete(memc->conn, key, strlen(key),
+ (time_t)seconds);
+ } else {
+ memc->rc = memcached_delete(memc->conn, key, strlen(key),
+ (time_t)0);
+ }
+ ast_log(LOG_WARNING,"errno:%d\tstr:%s\n", memc->rc,
+ memcached_strerror(memc->conn,memc->rc));
+ }
}
AST_RWLIST_UNLOCK(&memcaches);
@@ -276,14 +279,14 @@
);
if (ast_strlen_zero(parse)) {
- ast_log(LOG_WARNING, "MEMCACHE requires an argument, MEMCACHED(key[,expiry[,server]])=value\n");
+ ast_log(LOG_WARNING, "MEMCACHE requires an argument, MEMCACHED(<server>,<key>[,expiry])=value\n");
return -1;
}
AST_STANDARD_APP_ARGS(args, parse);
if (args.argc < 1) {
- ast_log(LOG_WARNING, "MEMCACHE requires an argument, MEMCACHED(key[,expiry])=value\n");
+ ast_log(LOG_WARNING, "MEMCACHE requires an argument, MEMCACHED(<server>,<key>[,expiry])=value\n");
return -1;
}
@@ -430,7 +433,7 @@
AST_LIST_INSERT_HEAD(&client->serv_list, serv, list);
} else if (!strcasecmp(var->name, "transportprotocol")) {
- if(!strcasecmp(var->value, "udp")) {
+ if (!strcasecmp(var->value, "udp")) {
client->transport = 1;
}
} else if (!strcasecmp(var->name, "binaryprotocol")) {
@@ -441,8 +444,9 @@
client->hash=1;/* Fixed HASH ATM */
/*ast_copy_string(client->hash, var->value, sizeof(client->hash));*/
} else if (!strcasecmp(var->name, "type")) {
- if (!strcmp(var->value, "mirror"))
- client->mirror = 1;
+ if (!strcmp(var->value, "mirror")) {
+ client->mirror = 1;
+ }
} else {
ast_log(LOG_WARNING, "Unknown configuration option: %s\n", var->name);
}
@@ -452,22 +456,21 @@
client->conn = memcached_create(NULL);
- //memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, uint64_t data);
- //MEMCACHED_BEHAVIOR_USE_UDP , MEMCACHED_BEHAVIOR_NO_BLOCK,
- //MEMCACHED_DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_CONSISTENT
- //MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS = n
-
- if(client->transport) {
+
+ if (client->transport) {
memcached_behavior_set(client->conn, MEMCACHED_BEHAVIOR_USE_UDP, 1);
- }
-
- if(client->protocol) {
+ ast_debug(3, "UDP Transport Active\n");
+ }
+
+ if (client->protocol) {
memcached_behavior_set(client->conn, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
- ast_log(LOG_WARNING,"Bin Proto Active: %d\n", client->protocol);
- }
-
- if(client->hash) {
+ ast_debug(3, "Bin Protocol Active\n");
+ }
+
+ if (client->hash) {
+ /*MEMCACHED_DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_CONSISTENT*/
memcached_behavior_set(client->conn, MEMCACHED_DISTRIBUTION_CONSISTENT, 1);
+ ast_debug(3, "Consistant Hash\n");
}
if (client->mirror) {
@@ -478,16 +481,16 @@
AST_LIST_TRAVERSE(&client->serv_list, serv, list) {
if (first) {
client->servers = memcached_server_list_append(NULL,
- serv->name, serv->port, &client->rc);
+ serv->name, serv->port, &client->rc);
first = 0;
} else {
client->servers = memcached_server_list_append(client->servers,
- serv->name, serv->port, &client->rc);
+ serv->name, serv->port, &client->rc);
}
no_serv++;
}
memcached_behavior_set(client->conn, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, no_serv);
- ast_log(LOG_WARNING,"No servers:%d\n", no_serv);
+ ast_debug(3, "Number of servers in group:%d\n", no_serv);
} else {
struct memc_servers *serv;
int first = 1;
@@ -496,19 +499,22 @@
AST_LIST_TRAVERSE(&client->serv_list, serv, list) {
if (first) {
client->servers = memcached_server_list_append(NULL,
- serv->name, serv->port, &client->rc);
+ serv->name, serv->port, &client->rc);
first = 0;
} else {
client->servers = memcached_server_list_append(client->servers,
- serv->name, serv->port, &client->rc);
+ serv->name, serv->port, &client->rc);
}
no_serv++;
}
- ast_log(LOG_WARNING,"No servers:%d\n", no_serv);
+ ast_debug(3, "Number of servers in group:%d\n", no_serv);
}
client->rc = memcached_server_push(client->conn, client->servers);
- ast_log(LOG_WARNING,"Push Error: %s\n", memcached_strerror(client->conn, client->rc));
+
+ if (client->rc == 1) {
+ ast_log(LOG_ERROR,"Push Error: %s\n", memcached_strerror(client->conn, client->rc));
+ }
AST_RWLIST_INSERT_HEAD(&memcaches, client, list);
@@ -564,7 +570,7 @@
cfg = ast_config_load(config, config_flags);
if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
- ast_log(LOG_NOTICE, "Unable to load config for func_odbc: %s\n", config);
+ ast_log(LOG_ERROR, "Unable to load config for func_memcache: %s\n", config);
return AST_MODULE_LOAD_DECLINE;
}
@@ -635,7 +641,7 @@
}
if (!cfg) {
- ast_log(LOG_WARNING, "Unable to load config for func_memcache: %s\n", config);
+ ast_log(LOG_ERROR, "Unable to load config for func_memcache: %s\n", config);
return -1;
}
@@ -655,7 +661,7 @@
return 0;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Memcache lookups",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "MemCache Function",
.load = load_module,
.unload = unload_module,
.reload = reload_module,
More information about the asterisk-commits
mailing list