Cleanup unload calls
[asterisk/asterisk.git] / channels / chan_iax.c
index 39515db..091c8a1 100755 (executable)
@@ -5330,6 +5330,33 @@ static struct ast_switch iax_switch =
        matchmore:              iax_matchmore,
 };
 
+static int __unload_module(void)
+{
+       int x;
+       /* Cancel the network thread, close the net socket */
+       pthread_cancel(netthreadid);
+       pthread_join(netthreadid, NULL);
+       close(netsocket);
+       for (x=0;x<AST_IAX_MAX_CALLS;x++)
+               if (iaxs[x])
+                       iax_destroy(x);
+       ast_manager_unregister( "IAXpeers" );
+       ast_cli_unregister(&cli_show_users);
+       ast_cli_unregister(&cli_show_channels);
+       ast_cli_unregister(&cli_show_peers);
+       ast_cli_unregister(&cli_set_jitter);
+       ast_cli_unregister(&cli_show_stats);
+       ast_cli_unregister(&cli_show_cache);
+       ast_unregister_switch(&iax_switch);
+       delete_users();
+       return 0;
+}
+
+int unload_module()
+{
+       return __unload_module();
+}
+
 int load_module(void)
 {
        char *config = "iax.conf";
@@ -5379,7 +5406,7 @@ int load_module(void)
 
        if (ast_channel_register(type, tdesc, iax_capability, iax_request)) {
                ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
-               unload_module();
+               __unload_module();
                return -1;
        }
 
@@ -5426,28 +5453,6 @@ char *description()
        return desc;
 }
 
-int unload_module()
-{
-       int x;
-       /* Cancel the network thread, close the net socket */
-       pthread_cancel(netthreadid);
-       pthread_join(netthreadid, NULL);
-       close(netsocket);
-       for (x=0;x<AST_IAX_MAX_CALLS;x++)
-               if (iaxs[x])
-                       iax_destroy(x);
-       ast_manager_unregister( "IAXpeers" );
-       ast_cli_unregister(&cli_show_users);
-       ast_cli_unregister(&cli_show_channels);
-       ast_cli_unregister(&cli_show_peers);
-       ast_cli_unregister(&cli_set_jitter);
-       ast_cli_unregister(&cli_show_stats);
-       ast_cli_unregister(&cli_show_cache);
-       ast_unregister_switch(&iax_switch);
-       delete_users();
-       return 0;
-}
-
 int usecount()
 {
        int res;