[asterisk-commits] russell: branch russell/iax2_performance r56404 - /team/russell/iax2_performa...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Feb 23 13:06:26 MST 2007


Author: russell
Date: Fri Feb 23 14:06:25 2007
New Revision: 56404

URL: http://svn.digium.com/view/asterisk?view=rev&rev=56404
Log:
sync with trunk and fix a couple buglets

Modified:
    team/russell/iax2_performance/channels/chan_iax2.c

Modified: team/russell/iax2_performance/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_performance/channels/chan_iax2.c?view=diff&rev=56404&r1=56403&r2=56404
==============================================================================
--- team/russell/iax2_performance/channels/chan_iax2.c (original)
+++ team/russell/iax2_performance/channels/chan_iax2.c Fri Feb 23 14:06:25 2007
@@ -636,6 +636,7 @@
 	unsigned int hash;
 };
 
+/* Somewhat arbitrary prime number */
 #define PVT_HASH_SIZE 563
 static AST_RWLIST_HEAD(pvt_list, chan_iax2_pvt) pvt_hash_tbl[PVT_HASH_SIZE];
 
@@ -1307,8 +1308,29 @@
 			ast_mutex_unlock(&iaxsl[pvt->callno]);
 			if (res > 0)
 				break;
-		}
+ 		}
 		AST_RWLIST_UNLOCK(&pvt_hash_tbl[hash]);
+		/* Not hashed yet, Look for an existing connection */
+		for (x=1;(res < 1) && (x<maxnontrunkcall);x++) {
+			ast_mutex_lock(&iaxsl[x]);
+			if (iaxs[x]) {
+				/* Look for an exact match */
+				if (match(sin, callno, dcallno, iaxs[x])) {
+					res = x;
+				}
+			}
+			ast_mutex_unlock(&iaxsl[x]);
+		}
+		for (x=TRUNK_CALL_START;(res < 1) && (x<maxtrunkcall);x++) {
+			ast_mutex_lock(&iaxsl[x]);
+			if (iaxs[x]) {
+				/* Look for an exact match */
+				if (match(sin, callno, dcallno, iaxs[x])) {
+					res = x;
+				}
+			}
+			ast_mutex_unlock(&iaxsl[x]);
+		}
 	}
 	if ((res < 1) && (new >= NEW_ALLOW)) {
 		if (!iax2_getpeername(*sin, host, sizeof(host), lockpeer))
@@ -1820,6 +1842,12 @@
 			pvt->owner = NULL;
 		iax2_destroy_helper(pvt);
 
+		if (pvt->hash) {
+			AST_RWLIST_WRLOCK(&pvt_hash_tbl[pvt->hash]);
+			AST_RWLIST_REMOVE(&pvt_hash_tbl[pvt->hash], pvt, entry);
+			AST_RWLIST_UNLOCK(&pvt_hash_tbl[pvt->hash]);
+		}
+
 		/* Already gone */
 		ast_set_flag(pvt, IAX_ALREADYGONE);	
 
@@ -1852,12 +1880,6 @@
 			/* gotta free up the stringfields */
 			ast_string_field_free_pools(pvt);
 			free(pvt);
-		}
-
-		if (pvt->hash) {
-			AST_RWLIST_WRLOCK(&pvt_hash_tbl[pvt->hash]);
-			AST_RWLIST_REMOVE(&pvt_hash_tbl[pvt->hash], pvt, entry);
-			AST_RWLIST_UNLOCK(&pvt_hash_tbl[pvt->hash]);
 		}
 	}
 	if (owner) {
@@ -6633,9 +6655,10 @@
 
 	if (!inaddrcmp(&sin, &iaxs[fr->callno]->addr) && !minivid &&
 		f.subclass != IAX_COMMAND_TXCNT &&		/* for attended transfer */
-		f.subclass != IAX_COMMAND_TXACC)		/* for attended transfer */
+		f.subclass != IAX_COMMAND_TXACC) {		/* for attended transfer */
 		iaxs[fr->callno]->peercallno = (unsigned short)(ntohs(mh->callno) & ~IAX_FLAG_FULL);
 		hash_on_peer(iaxs[fr->callno]);
+	}
 	if (ntohs(mh->callno) & IAX_FLAG_FULL) {
 		if (option_debug  && iaxdebug)
 			ast_log(LOG_DEBUG, "Received packet %d, (%d, %d)\n", fh->oseqno, f.frametype, f.subclass);
@@ -10049,19 +10072,10 @@
 #endif /* IAXTESTS */
 };
 
-static int unload_module(void)
+static int __unload_module(void)
 {
 	struct iax2_thread *thread = NULL;
 	int x;
-
-	ast_custom_function_unregister(&iaxpeer_function);
-	ast_custom_function_unregister(&iaxvar_function);
-	ast_manager_unregister( "IAXpeers" );
-	ast_manager_unregister( "IAXnetstats" );
-	ast_unregister_application(papp);
-	ast_cli_unregister_multiple(cli_iax2, sizeof(cli_iax2) / sizeof(struct ast_cli_entry));
-	ast_unregister_switch(&iax2_switch);
-	ast_channel_unregister(&iax2_tech);
 
 	/* Make sure threads do not hold shared resources when they are canceled */
 	
@@ -10114,10 +10128,15 @@
 		usleep(10000);
 	
 	ast_netsock_release(netsock);
-	for (x = 0; x < IAX_MAX_CALLS; x++) {
+	for (x=0;x<IAX_MAX_CALLS;x++)
 		if (iaxs[x])
 			iax2_destroy(x);
-	}
+	ast_manager_unregister( "IAXpeers" );
+	ast_manager_unregister( "IAXnetstats" );
+	ast_unregister_application(papp);
+	ast_cli_unregister_multiple(cli_iax2, sizeof(cli_iax2) / sizeof(struct ast_cli_entry));
+	ast_unregister_switch(&iax2_switch);
+	ast_channel_unregister(&iax2_tech);
 	delete_users();
 	iax_provision_unload();
 	sched_context_destroy(sched);
@@ -10130,6 +10149,14 @@
 
 	return 0;
 }
+
+static int unload_module(void)
+{
+	ast_custom_function_unregister(&iaxpeer_function);
+	ast_custom_function_unregister(&iaxvar_function);
+	return __unload_module();
+}
+
 
 /*! \brief Load IAX2 module, load configuraiton ---*/
 static int load_module(void)
@@ -10162,7 +10189,7 @@
 		ast_mutex_init(&iaxsl[x]);
 
 	for (x = 0; x < PVT_HASH_SIZE; x++)
-		AST_RWLIST_HEAD_INIT(&pvt_hash_tbl[x]);	
+		AST_RWLIST_HEAD_INIT(&pvt_hash_tbl[x]);
 
 	ast_cond_init(&sched_cond, NULL);
 
@@ -10198,6 +10225,7 @@
 
  	if (ast_channel_register(&iax2_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", "IAX2");
+		__unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -10206,6 +10234,7 @@
 
 	if (start_network_thread()) {
 		ast_log(LOG_ERROR, "Unable to start network thread\n");
+		__unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	} else if (option_verbose > 1)
 		ast_verbose(VERBOSE_PREFIX_2 "IAX Ready and Listening\n");



More information about the asterisk-commits mailing list