[asterisk-commits] snuffy: branch snuffy/func_memcache r230421 - in /team/snuffy/func_memcache: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 18 05:14:58 CST 2009


Author: snuffy
Date: Wed Nov 18 05:14:54 2009
New Revision: 230421

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=230421
Log:
More random updates..
Comments welcome ppl ;)

Modified:
    team/snuffy/func_memcache/configs/func_memcache.conf.sample
    team/snuffy/func_memcache/funcs/func_memcache.c

Modified: team/snuffy/func_memcache/configs/func_memcache.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/snuffy/func_memcache/configs/func_memcache.conf.sample?view=diff&rev=230421&r1=230420&r2=230421
==============================================================================
--- team/snuffy/func_memcache/configs/func_memcache.conf.sample (original)
+++ team/snuffy/func_memcache/configs/func_memcache.conf.sample Wed Nov 18 05:14:54 2009
@@ -1,14 +1,13 @@
 [general]
 ; Default Transport Protocol, either tcp or udp
+; If you choose to use udp, some features may not be available
 ;transportprotocol=tcp
 ;
-; Default Memcache Protocol is text
 ; Doing multiple gets, or high usage you may see improvement using binary protocol.
-; binaryprotocol=no
+; memcacheprotocol=text
 ;
 ; Hash Method, only consistant for now
 ; distrubitehash=consistant
-; 
 ;
 ;
 ;
@@ -19,14 +18,14 @@
 ;[mirror]
 ;server=localhost:11211
 ;mirrorserver=localhost:11212
-;binaryprotocol=yes
+;memcacheprotocol=binary
 ;replicas=2
 ;
 ;
 
 [testmem]
 server=127.0.0.1:21000
-binaryprotocol=yes
+memcacheprotocol=binary
 
 [manycaches]
 server=abc.123.com:13333

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=230421&r1=230420&r2=230421
==============================================================================
--- team/snuffy/func_memcache/funcs/func_memcache.c (original)
+++ team/snuffy/func_memcache/funcs/func_memcache.c Wed Nov 18 05:14:54 2009
@@ -102,10 +102,13 @@
 
 static const char config[] = "func_memcache.conf";
 
+/*! \brief Memcache information structure */
 struct memcache_con {
 	char name[80];
-	int protocol; /* 0= udp 1=tcp*/
-	int transport; /* 0=text 1=bin */
+	/*! Transport Protocol either UDP/TCP */
+	int trans_protocol;
+	/*! Memcache Protocol either TEXT/BINARY */
+	int memc_protocol;
 	int mirror;
 	unsigned int flags; /* bitmasking instead? */
 	char hash; /* consistant (cluster) or other */
@@ -137,8 +140,10 @@
 	AST_RWLIST_TRAVERSE(&memcaches, memc, list) {
 		if (!strcmp(memc->name, server)) {
 			value = memcached_get(memc->conn, key, strlen(key), &value_len, &flags, &memc->rc);
-			ast_log(LOG_WARNING,"errno:%d\tstr:%s\n", memc->rc, 
-				memcached_strerror(memc->conn, memc->rc));
+			if (memc->rc != 0) {
+				ast_log(LOG_ERROR, "Memcache Error: %s\n", 
+					memcached_strerror(memc->conn, memc->rc));
+			}
 		}
 	}
 	
@@ -171,7 +176,11 @@
 						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));
+
+			if (memc->rc != 0) {
+				ast_log(LOG_ERROR, "Memcache Error: %s\n", 
+					memcached_strerror(memc->conn, memc->rc));
+			}
 		}
 	}
 	AST_RWLIST_UNLOCK(&memcaches);
@@ -199,8 +208,11 @@
 				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 (memc->rc != 0) {
+				ast_log(LOG_ERROR, "Memcache Error: %s\n", 
+					memcached_strerror(memc->conn, memc->rc));
+			}
 		}
 	}
 	AST_RWLIST_UNLOCK(&memcaches);
@@ -236,10 +248,10 @@
 
 	if (fn_memcache_get(args.key, args.server, buf, len)) {
 		ast_debug(1, "MEMCACHE: %s not found in cache.\n", args.key);
-		strcpy(buf,"0");
+		strcpy(buf, "0");
 	} else {
 		pbx_builtin_setvar_helper(chan, "MEMCACHE_RESULT", buf);
-		strcpy(buf,"1");
+		strcpy(buf, "1");
 	}
 
 	return 0;
@@ -275,7 +287,7 @@
 		return -1;
 	}	
 	if (fn_memcache_put(args.key, args.server, args.expiry, value)) {
-		ast_log(LOG_WARNING, "MEMCACHE: Error writing %s to server.\n", value);
+		ast_log(LOG_WARNING, "MEMCACHE: Error writing key:%s & Value:%s to server.\n", args.key, value);
 		return -1;
 	}
 
@@ -306,10 +318,10 @@
 
 	if (fn_memcache_get(args.key, args.server, buf, len)) {
 		ast_debug(1, "MEMCACHE: %s not found in cache.\n", args.key);
-		strcpy(buf,"0");
+		strcpy(buf, "0");
 	} else {
 		pbx_builtin_setvar_helper(chan, "MEMCACHE_RESULT", buf);
-		strcpy(buf,"1");
+		strcpy(buf, "1");
 	}
 
 	return 0;
@@ -387,8 +399,8 @@
 		return 1;
 	}
 
-	client->protocol = 0;
-	client->transport = 0;
+	client->trans_protocol = 0;
+	client->memc_protocol = 0;
 
 	ast_copy_string(client->name, cat, sizeof(client->name));
 
@@ -415,11 +427,11 @@
 
 		} else if (!strcasecmp(var->name, "transportprotocol")) {
 			if (!strcasecmp(var->value, "udp")) {
-				client->transport = 1;
-			}
-		} else if (!strcasecmp(var->name, "binaryprotocol")) {
-			if (!strcasecmp(var->value, "yes")) {
-				client->protocol = 1;
+				client->trans_protocol = 1;
+			}
+		} else if (!strcasecmp(var->name, "memcacheprotocol")) {
+			if (!strcasecmp(var->value, "binary")) {
+				client->memc_protocol = 1;
 			}
 		} else if (!strcasecmp(var->name, "distributehash")) {
 			client->hash=1;/* Fixed HASH ATM */
@@ -437,12 +449,12 @@
 
 	client->conn = memcached_create(NULL);
 
-	if (client->transport) {
+	if (client->trans_protocol) {
 		memcached_behavior_set(client->conn, MEMCACHED_BEHAVIOR_USE_UDP, 1);
 		ast_debug(3, "UDP Transport Active\n");
 	}
 
-	if (client->protocol) {
+	if (client->memc_protocol) {
 		memcached_behavior_set(client->conn, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
 		ast_debug(3, "Bin Protocol Active\n");
 	}
@@ -492,8 +504,18 @@
 
 	client->rc = memcached_server_push(client->conn, client->servers);
 
-	if (client->rc == 1) {
+	/* Error occurred on final connection setup, free related structs/list */
+	if (client->rc != 0) {
 		ast_log(LOG_ERROR, "Push Error: %s\n", memcached_strerror(client->conn, client->rc));
+  		while (!AST_LIST_EMPTY(&client->serv_list)) {
+			struct memc_servers *serv;
+			serv = AST_LIST_REMOVE_HEAD(&client->serv_list, list);
+			ast_free(serv);
+		}
+		memcached_server_list_free(client->servers);
+		memcached_free(client->conn);
+		ast_free(client);
+		return 1;
 	}
 
 	AST_RWLIST_INSERT_HEAD(&memcaches, client, list);
@@ -583,7 +605,7 @@
 			serv = AST_LIST_REMOVE_HEAD(&client->serv_list, list);
 			ast_free(serv);
 		}
-		memcached_server_free(client->servers);
+		memcached_server_list_free(client->servers);
 		memcached_free(client->conn);
 		ast_free(client);
 	}




More information about the asterisk-commits mailing list