[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r140557 - /team/jdixon/chan_usbradio-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Sep 2 08:59:33 CDT 2008
Author: jdixon
Date: Tue Sep 2 08:59:32 2008
New Revision: 140557
URL: http://svn.digium.com/view/asterisk?view=rev&rev=140557
Log:
Added nicer error handling to chan_echolink
Modified:
team/jdixon/chan_usbradio-1.4/channels/chan_echolink.c
Modified: team/jdixon/chan_usbradio-1.4/channels/chan_echolink.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/channels/chan_echolink.c?view=diff&rev=140557&r1=140556&r2=140557
==============================================================================
--- team/jdixon/chan_usbradio-1.4/channels/chan_echolink.c (original)
+++ team/jdixon/chan_usbradio-1.4/channels/chan_echolink.c Tue Sep 2 08:59:32 2008
@@ -32,7 +32,7 @@
<depend>zlib</depend>
***/
-/* Version 0.14, 08/27/2008
+/* Version 0.15, 09/02/2008
Echolink channel driver for Asterisk/app_rpt.
A lot more has to be added,
Here is what comes to mind first:
@@ -100,6 +100,8 @@
#include <netinet/in.h>
#include <netdb.h>
#include <zlib.h>
+#include <pthread.h>
+#include <signal.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
@@ -113,6 +115,7 @@
#include "asterisk/dsp.h"
#include "asterisk/translate.h"
#include "asterisk/astdb.h"
+#include "asterisk/cli.h"
#define MAX_RXKEY_TIME 4
@@ -221,7 +224,7 @@
struct gsmVoice_t audio_all_but_one;
struct gsmVoice_t audio_all;
struct el_node el_node_test;
-
+ pthread_t el_reader_thread;
} ;
struct el_rxqast {
@@ -311,10 +314,11 @@
static void *el_node_list = NULL;
/* Echolink registration thread */
-static pthread_t el_register_thread;
-static pthread_t el_reader_thread;
-static pthread_t el_directory_thread;
+static pthread_t el_register_thread = 0;
+static pthread_t el_directory_thread = 0;
static int run_forever = 1;
+static int killing = 0;
+static int nullfd = -1;
static char *config = "echolink.conf";
@@ -368,6 +372,25 @@
.send_digit_begin = el_digit_begin,
.send_digit_end = el_digit_end,
};
+
+static void mythread_exit(void *nothing)
+{
+int i;
+
+ if (killing) pthread_exit(NULL);
+ killing = 1;
+ run_forever = 0;
+ for(i = 0; i < ninstances; i++)
+ {
+ if (instances[i]->el_reader_thread)
+ pthread_kill(instances[i]->el_reader_thread,SIGTERM);
+ }
+ if (el_register_thread) pthread_kill(el_register_thread,SIGTERM);
+ if (el_directory_thread) pthread_kill(el_directory_thread,SIGTERM);
+ ast_log(LOG_ERROR,"Exiting chan_echolink, FATAL ERROR!!\n");
+ ast_cli_command(nullfd,"rpt restart");
+ pthread_exit(NULL);
+}
static int rtcp_make_sdes(unsigned char *pkt, int pktLen, char *call, char *name)
{
@@ -1341,6 +1364,7 @@
/* First, take us out of the channel loop */
ast_channel_unregister(&el_tech);
for(n = 0; n < ninstances; n++) ast_free(instances[n]);
+ if (nullfd != -1) close(nullfd);
return 0;
}
@@ -1802,7 +1826,8 @@
else if (rc == 0) sleep(1800);
}
ast_log(LOG_NOTICE, "Echolink directory thread exited.\n");
- pthread_exit(NULL);
+ mythread_exit(NULL);
+ return NULL;
}
static void *el_register(void *data)
@@ -1837,7 +1862,8 @@
Echolink deactivates this node within 6 minutes
*/
ast_log(LOG_NOTICE, "Echolink registration thread exited.\n");
- pthread_exit(NULL);
+ mythread_exit(NULL);
+ return NULL;
}
static int do_new_call(struct el_instance *instp, struct el_pvt *p, char *call, char *name)
@@ -1856,7 +1882,7 @@
{
ast_log(LOG_ERROR, "Cannot find DB entry for %s\n",dbstr);
free(el_node_key);
- return -1;
+ return 1;
}
el_node_key->nodenum = atoi(nodestr);
el_node_key->countdown = instp->rtcptimeout;
@@ -1920,7 +1946,8 @@
{
struct el_instance *instp = (struct el_instance *)data;
char buf[1024];
- struct sockaddr_in sin;
+ unsigned char bye[40];
+ struct sockaddr_in sin,sin1;
int i,x;
struct el_rxqast *qpast;
struct el_rxqel *qpel;
@@ -1959,7 +1986,7 @@
if (i < 0)
{
ast_log(LOG_ERROR,"Error in select()\n");
- pthread_exit(NULL);
+ mythread_exit(NULL);
}
ast_mutex_lock(&instp->lock);
if (FD_ISSET(instp->ctrl_sock,fds)) /* if a ctrl packet */
@@ -2031,10 +2058,25 @@
}
else /* otherwise its a new request */
{
- if (do_new_call(instp,NULL,call,name) < 0)
+ i = do_new_call(instp,NULL,call,name);
+ if (i < 0)
{
ast_mutex_unlock(&instp->lock);
- pthread_exit(NULL);
+ mythread_exit(NULL);
+ }
+ if (i)
+ {
+ if (debug) ast_log(LOG_DEBUG,"Sent bye to IP address %s\n",
+ instp->el_node_test.ip);
+ x = rtcp_make_bye(bye,"UN-AUTHORIZED");
+ sin1.sin_family = AF_INET;
+ sin1.sin_addr.s_addr = inet_addr(instp->el_node_test.ip);
+ sin1.sin_port = htons(instp->ctrl_port);
+ for (i = 0; i < 20; i++)
+ {
+ sendto(instp->ctrl_sock, bye, x,
+ 0,(struct sockaddr *)&sin1,sizeof(sin1));
+ }
}
}
}
@@ -2105,7 +2147,7 @@
{
ast_log(LOG_NOTICE,"Cannot malloc for qpast\n");
ast_mutex_unlock(&instp->lock);
- pthread_exit(NULL);
+ mythread_exit(NULL);
}
memcpy(qpast->buf,((struct gsmVoice_t *)buf)->data +
(GSM_FRAME_SIZE * i),GSM_FRAME_SIZE);
@@ -2136,7 +2178,8 @@
}
ast_mutex_unlock(&instp->lock);
ast_log(LOG_NOTICE, "Echolink read thread exited.\n");
- pthread_exit(NULL);
+ mythread_exit(NULL);
+ return NULL;
}
static int store_config(struct ast_config *cfg,char *ctg)
@@ -2340,7 +2383,7 @@
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ast_pthread_create(&el_register_thread,&attr,el_register,(void *)instp);
- ast_pthread_create(&el_reader_thread,&attr,el_reader,(void *)instp);
+ ast_pthread_create(&instp->el_reader_thread,&attr,el_reader,(void *)instp);
instances[ninstances++] = instp;
ast_log(LOG_NOTICE, "Echolink/%s listening on %s port %s\n", instp->name, instp->ipaddr,instp->port);
@@ -2397,7 +2440,7 @@
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
return AST_MODULE_LOAD_DECLINE;
}
-
+ nullfd = open("/dev/null",O_RDWR);
return 0;
}
More information about the asterisk-commits
mailing list