forked from Mirrors/freeswitch
performance tuning
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@684 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
845235dee9
commit
28d431aefd
@ -87,6 +87,7 @@
|
||||
#pragma comment(lib, "Winmm")
|
||||
#endif
|
||||
|
||||
#define ZAP_THREAD_STACKSIZE 240 * 1024
|
||||
#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL };
|
||||
#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type);
|
||||
#define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
|
||||
|
@ -97,7 +97,8 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = {
|
||||
{15, LPWRAP_PRI_EVENT_HANGUP_REQ, "HANGUP_REQ"},
|
||||
{16, LPWRAP_PRI_EVENT_NOTIFY, "NOTIFY"},
|
||||
{17, LPWRAP_PRI_EVENT_PROGRESS, "PROGRESS"},
|
||||
{18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"}
|
||||
{18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"},
|
||||
{19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"}
|
||||
};
|
||||
|
||||
#define LINE "--------------------------------------------------------------------------------"
|
||||
@ -114,8 +115,9 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
|
||||
int res;
|
||||
|
||||
if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) {
|
||||
printf("D-READ FAIL! [%s]\n", spri->zdchan->last_error);
|
||||
return 0;
|
||||
zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span, spri->zdchan->last_error);
|
||||
zap_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
return -1;
|
||||
}
|
||||
res = (int)len;
|
||||
memset(&((unsigned char*)buf)[res],0,2);
|
||||
@ -133,8 +135,9 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
|
||||
zap_size_t len = buflen -2;
|
||||
|
||||
if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) {
|
||||
printf("D-WRITE FAIL! [%s]\n", spri->zdchan->last_error);
|
||||
return 0;
|
||||
zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span, spri->zdchan->last_error);
|
||||
zap_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0);
|
||||
@ -155,6 +158,7 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int
|
||||
spri->span = span;
|
||||
pri_set_debug(spri->pri, debug);
|
||||
ret = 0;
|
||||
zap_set_flag(spri, LPWRAP_PRI_READY);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to create PRI\n");
|
||||
}
|
||||
@ -168,6 +172,7 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
fd_set rfds, efds;
|
||||
struct timeval now = {0,0}, *next;
|
||||
pri_event *event;
|
||||
event_handler handler;
|
||||
int sel;
|
||||
|
||||
if (spri->on_loop) {
|
||||
@ -210,7 +215,6 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
}
|
||||
|
||||
if (event) {
|
||||
event_handler handler;
|
||||
/* 0 is catchall event handler */
|
||||
if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
|
||||
handler(spri, event->e, event);
|
||||
@ -219,16 +223,25 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
}
|
||||
}
|
||||
|
||||
return sel;
|
||||
if (zap_test_flag(spri, LPWRAP_PRI_READY)) {
|
||||
return sel;
|
||||
}
|
||||
|
||||
if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_IO_FAIL] ? spri->eventmap[LPWRAP_PRI_EVENT_IO_FAIL] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
|
||||
handler(spri, LPWRAP_PRI_EVENT_IO_FAIL, NULL);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int lpwrap_run_pri(struct lpwrap_pri *spri)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
||||
for (;;){
|
||||
ret=lpwrap_one_loop(spri);
|
||||
if (ret < 0){
|
||||
ret = lpwrap_one_loop(spri);
|
||||
|
||||
if (ret < 0) {
|
||||
|
||||
#ifndef WIN32 //This needs to be adressed fror WIN32 still
|
||||
if (errno == EINTR){
|
||||
@ -236,9 +249,8 @@ int lpwrap_run_pri(struct lpwrap_pri *spri)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
printf("Error = %i\n",ret);
|
||||
perror("Lpwrap Run Pri: ");
|
||||
break;
|
||||
zap_log(ZAP_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,8 @@ typedef enum {
|
||||
LPWRAP_PRI_EVENT_HANGUP_REQ = PRI_EVENT_HANGUP_REQ,
|
||||
LPWRAP_PRI_EVENT_NOTIFY = PRI_EVENT_NOTIFY,
|
||||
LPWRAP_PRI_EVENT_PROGRESS = PRI_EVENT_PROGRESS,
|
||||
LPWRAP_PRI_EVENT_KEYPAD_DIGIT = PRI_EVENT_KEYPAD_DIGIT
|
||||
LPWRAP_PRI_EVENT_KEYPAD_DIGIT = PRI_EVENT_KEYPAD_DIGIT,
|
||||
LPWRAP_PRI_EVENT_IO_FAIL = 19
|
||||
} lpwrap_pri_event_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -704,28 +704,70 @@ static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev
|
||||
|
||||
|
||||
|
||||
static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent)
|
||||
{
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span, event_type, lpwrap_pri_event_str(event_type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void *zap_libpri_run(zap_thread_t *me, void *obj)
|
||||
{
|
||||
zap_span_t *span = (zap_span_t *) obj;
|
||||
zap_libpri_data_t *isdn_data = span->signal_data;
|
||||
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_ANY, on_anything);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RING, on_ring);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RINGING, on_ringing);
|
||||
//LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_SETUP_ACK, on_proceed);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_PROCEEDING, on_proceed);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_ANSWER, on_answer);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_DCHAN_UP, on_dchan_up);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_DCHAN_DOWN, on_dchan_down);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_HANGUP_REQ, on_hangup);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_HANGUP, on_hangup);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_INFO_RECEIVED, on_info);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RESTART, on_restart);
|
||||
|
||||
isdn_data->spri.on_loop = check_flags;
|
||||
isdn_data->spri.private_info = span;
|
||||
int x, i;
|
||||
|
||||
lpwrap_run_pri(&isdn_data->spri);
|
||||
while(zap_running()) {
|
||||
x = 0;
|
||||
|
||||
for(i = 1; i <= span->chan_count; i++) {
|
||||
if (span->channels[i]->type == ZAP_CHAN_TYPE_DQ921) {
|
||||
if (zap_channel_open(span->span_id, i, &isdn_data->dchan) == ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, isdn_data->dchan->span_id, isdn_data->dchan->chan_id);
|
||||
isdn_data->dchan->state = ZAP_CHANNEL_STATE_UP;
|
||||
x++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (x && lpwrap_init_pri(&isdn_data->spri,
|
||||
span->span_id, // span
|
||||
isdn_data->dchan, // dchan
|
||||
isdn_data->pswitch,
|
||||
isdn_data->node,
|
||||
isdn_data->debug) < 0) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "PRI init FAIL!");
|
||||
} else {
|
||||
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_ANY, on_anything);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RING, on_ring);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RINGING, on_ringing);
|
||||
//LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_SETUP_ACK, on_proceed);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_PROCEEDING, on_proceed);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_ANSWER, on_answer);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_DCHAN_UP, on_dchan_up);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_DCHAN_DOWN, on_dchan_down);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_HANGUP_REQ, on_hangup);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_HANGUP, on_hangup);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_INFO_RECEIVED, on_info);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_RESTART, on_restart);
|
||||
LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_IO_FAIL, on_io_fail);
|
||||
|
||||
|
||||
isdn_data->spri.on_loop = check_flags;
|
||||
isdn_data->spri.private_info = span;
|
||||
|
||||
lpwrap_run_pri(&isdn_data->spri);
|
||||
zap_channel_close(&isdn_data->dchan);
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span);
|
||||
zap_sleep(5000);
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
@ -736,9 +778,10 @@ static zap_status_t zap_libpri_start(zap_span_t *span)
|
||||
zap_status_t ret;
|
||||
|
||||
zap_libpri_data_t *isdn_data = span->signal_data;
|
||||
zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING);
|
||||
|
||||
zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING);
|
||||
ret = zap_thread_create_detached(zap_libpri_run, span);
|
||||
|
||||
if (ret != ZAP_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
@ -806,7 +849,7 @@ static int str2dp(char *dp)
|
||||
static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span)
|
||||
{
|
||||
uint32_t i, x = 0;
|
||||
zap_channel_t *dchans[2] = {0};
|
||||
//zap_channel_t *dchans[2] = {0};
|
||||
zap_libpri_data_t *isdn_data;
|
||||
char *var, *val;
|
||||
int32_t opts = 0;
|
||||
@ -823,19 +866,23 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span)
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Span has more than 2 D-Channels!");
|
||||
return ZAP_FAIL;
|
||||
} else {
|
||||
#if 0
|
||||
if (zap_channel_open(span->span_id, i, &dchans[x]) == ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, dchans[x]->span_id, dchans[x]->chan_id);
|
||||
dchans[x]->state = ZAP_CHANNEL_STATE_UP;
|
||||
x++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!x) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
isdn_data = malloc(sizeof(*isdn_data));
|
||||
assert(isdn_data != NULL);
|
||||
@ -888,21 +935,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span)
|
||||
|
||||
span->start = zap_libpri_start;
|
||||
isdn_data->sig_cb = sig_cb;
|
||||
isdn_data->dchans[0] = dchans[0];
|
||||
isdn_data->dchans[1] = dchans[1];
|
||||
isdn_data->dchan = isdn_data->dchans[0];
|
||||
//isdn_data->dchans[0] = dchans[0];
|
||||
//isdn_data->dchans[1] = dchans[1];
|
||||
//isdn_data->dchan = isdn_data->dchans[0];
|
||||
|
||||
isdn_data->debug = parse_debug(debug);
|
||||
|
||||
if (lpwrap_init_pri(&isdn_data->spri,
|
||||
span->span_id, // span
|
||||
isdn_data->dchan, // dchan
|
||||
isdn_data->pswitch,
|
||||
isdn_data->node,
|
||||
isdn_data->debug) < 0) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "PRI init FAIL!");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
span->signal_data = isdn_data;
|
||||
span->signal_type = ZAP_SIGTYPE_ISDN;
|
||||
|
@ -2563,6 +2563,8 @@ zap_status_t zap_global_init(void)
|
||||
|
||||
time_init();
|
||||
|
||||
zap_thread_override_default_stacksize(ZAP_THREAD_STACKSIZE);
|
||||
|
||||
memset(&interfaces, 0, sizeof(interfaces));
|
||||
globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
||||
globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
||||
|
Loading…
Reference in New Issue
Block a user