[asterisk-commits] file: trunk r43461 - in /trunk/channels: chan_iax2.c chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Sep 21 15:53:17 MST 2006


Author: file
Date: Thu Sep 21 17:53:17 2006
New Revision: 43461

URL: http://svn.digium.com/view/asterisk?rev=43461&view=rev
Log:
Oh look more changes, but these are my own! (Clean up module load functions)

Modified:
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=43461&r1=43460&r2=43461&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Thu Sep 21 17:53:17 2006
@@ -9890,8 +9890,7 @@
 static int load_module(void)
 {
 	char *config = "iax.conf";
-	int res = 0;
-	int x;
+	int x = 0;
 	struct iax2_registry *reg = NULL;
 	struct iax2_peer *peer = NULL;
 	
@@ -9915,20 +9914,25 @@
 
 	for (x=0;x<IAX_MAX_CALLS;x++)
 		ast_mutex_init(&iaxsl[x]);
-	
-	io = io_context_create();
-	sched = sched_context_create();
-	
-	if (!io || !sched) {
-		ast_log(LOG_ERROR, "Out of memory\n");
-		return -1;
-	}
-
-	netsock = ast_netsock_list_alloc();
-	if (!netsock) {
-		ast_log(LOG_ERROR, "Could not allocate netsock list.\n");
-		return -1;
-	}
+
+	if (!(sched = sched_context_create())) {
+		ast_log(LOG_ERROR, "Failed to create scheduler context\n");
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	if (!(io = io_context_create())) {
+		ast_log(LOG_ERROR, "Failed to create I/O context\n");
+		sched_context_destroy(sched);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	if (!(netsock = ast_netsock_list_alloc())) {
+		ast_log(LOG_ERROR, "Failed to create netsock list\n");
+		io_context_destroy(io);
+		sched_context_destroy(sched);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
 	ast_netsock_init(netsock);
 
 	ast_mutex_init(&waresl.lock);
@@ -9946,23 +9950,22 @@
  	if (ast_channel_register(&iax2_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", "IAX2");
 		__unload_module();
-		return -1;
+		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	if (ast_register_switch(&iax2_switch)) 
 		ast_log(LOG_ERROR, "Unable to register IAX switch\n");
 
-	res = start_network_thread();
-	if (!res) {
-		if (option_verbose > 1) 
-			ast_verbose(VERBOSE_PREFIX_2 "IAX Ready and Listening\n");
-	} else {
+	if (start_network_thread()) {
 		ast_log(LOG_ERROR, "Unable to start network thread\n");
-		ast_netsock_release(netsock);
-	}
+		__unload_module();
+		return AST_MODULE_LOAD_FAILURE;
+	} else if (option_verbose > 1)
+		ast_verbose(VERBOSE_PREFIX_2 "IAX Ready and Listening\n");
 
 	for (reg = registrations; reg; reg = reg->next)
 		iax2_do_register(reg);
+
 	AST_LIST_LOCK(&peers);
 	AST_LIST_TRAVERSE(&peers, peer, entry) {
 		if (peer->sockfd < 0)
@@ -9970,9 +9973,11 @@
 		iax2_poke_peer(peer, 0);
 	}
 	AST_LIST_UNLOCK(&peers);
+
 	reload_firmware();
 	iax_provision_reload();
-	return res;
+
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Inter Asterisk eXchange (Ver 2)",

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=43461&r1=43460&r2=43461&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Thu Sep 21 17:53:17 2006
@@ -16714,22 +16714,28 @@
 	ASTOBJ_CONTAINER_INIT(&peerl);	/* Peer object list */
 	ASTOBJ_CONTAINER_INIT(&regl);	/* Registry object list */
 
-	sched = sched_context_create();
-	if (!sched) {
-		ast_log(LOG_WARNING, "Unable to create schedule context\n");
-	}
-
-	io = io_context_create();
-	if (!io) {
-		ast_log(LOG_WARNING, "Unable to create I/O context\n");
-	}
+	if (!(sched = sched_context_create())) {
+		ast_log(LOG_ERROR, "Unable to create scheduler context\n");
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	if (!(io = io_context_create())) {
+		ast_log(LOG_ERROR, "Unable to create I/O context\n");
+		sched_context_destroy(sched);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
 	sip_reloadreason = CHANNEL_MODULE_LOAD;
+
 	if(reload_config(sip_reloadreason))	/* Load the configuration from sip.conf */
 		return AST_MODULE_LOAD_DECLINE;
+
 	/* Make sure we can register our sip channel type */
 	if (ast_channel_register(&sip_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
-		return -1;
+		io_context_destroy(io);
+		sched_context_destroy(sched);
+		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	/* Register all CLI functions for SIP */
@@ -16763,7 +16769,7 @@
 	/* And start the monitor for the first time */
 	restart_monitor();
 
-	return 0;
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)



More information about the asterisk-commits mailing list