提交 f258a0f9 authored 作者: Anthony Minessale's avatar Anthony Minessale

fix unclean shutdown

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@693 a93c3328-9c30-0410-af19-c9cd2b2d52af
上级 2dcc9f11
......@@ -543,6 +543,7 @@ struct zap_span {
zio_channel_outgoing_call_t outgoing_call;
zio_channel_request_t channel_request;
zap_span_start_t start;
zap_span_stop_t stop;
void *mod_data;
char *type;
char *dtmf_hangup;
......
......@@ -282,7 +282,9 @@ typedef enum {
ZAP_SPAN_CONFIGURED = (1 << 0),
ZAP_SPAN_READY = (1 << 1),
ZAP_SPAN_STATE_CHANGE = (1 << 2),
ZAP_SPAN_SUSPENDED = (1 << 3)
ZAP_SPAN_SUSPENDED = (1 << 3),
ZAP_SPAN_IN_THREAD = (1 << 4),
ZAP_SPAN_STOP_THREAD = (1 << 5)
} zap_span_flag_t;
typedef enum {
......@@ -529,6 +531,7 @@ typedef struct value zap_hash_val_t;
typedef struct zap_bitstream zap_bitstream_t;
typedef struct zap_fsk_modulator zap_fsk_modulator_t;
typedef zap_status_t (*zap_span_start_t)(zap_span_t *span);
typedef zap_status_t (*zap_span_stop_t)(zap_span_t *span);
typedef enum {
ZAP_CAUSE_NONE = 0,
......
......@@ -98,7 +98,8 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = {
{16, LPWRAP_PRI_EVENT_NOTIFY, "NOTIFY"},
{17, LPWRAP_PRI_EVENT_PROGRESS, "PROGRESS"},
{18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"},
{19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"}
{19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"},
{20, LPWRAP_PRI_EVENT_TIME_CHECK, "TIME_CHECK"}
};
#define LINE "--------------------------------------------------------------------------------"
......@@ -114,8 +115,8 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
zap_size_t len = buflen;
int res;
if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span, spri->zdchan->last_error);
if (zap_channel_read(spri->dchan, buf, &len) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
zap_clear_flag(spri, LPWRAP_PRI_READY);
return -1;
}
......@@ -134,8 +135,8 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
zap_size_t len = buflen -2;
if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span, spri->zdchan->last_error);
if (zap_channel_write(spri->dchan, buf, buflen, &len) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
zap_clear_flag(spri, LPWRAP_PRI_READY);
return -1;
}
......@@ -146,15 +147,15 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
return (int) buflen;
}
int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug)
int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug)
{
int ret = -1;
memset(spri, 0, sizeof(struct lpwrap_pri));
spri->zdchan = dchan;
spri->dchan = dchan;
if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){
if ((spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){
spri->span = span;
pri_set_debug(spri->pri, debug);
ret = 0;
......@@ -203,6 +204,13 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
event = NULL;
if (!sel) {
if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] ?
spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
if (handler(spri, LPWRAP_PRI_EVENT_TIME_CHECK, NULL) < 0) {
return -1;
}
}
if ((next = pri_schedule_next(spri->pri))) {
gettimeofday(&now, NULL);
if (now.tv_sec >= next->tv_sec && (now.tv_usec >= next->tv_usec || next->tv_usec <= 100000)) {
......
......@@ -59,7 +59,8 @@ typedef enum {
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_IO_FAIL = 19
LPWRAP_PRI_EVENT_IO_FAIL = 19,
LPWRAP_PRI_EVENT_TIME_CHECK = 20
} lpwrap_pri_event_t;
typedef enum {
......@@ -92,13 +93,12 @@ typedef int (*loop_handler)(struct lpwrap_pri *);
struct lpwrap_pri {
struct pri *pri;
int span;
int dchan;
zap_span_t *span;
zap_channel_t *dchan;
unsigned int flags;
void *private_info;
event_handler eventmap[MAX_EVENT+1];
loop_handler on_loop;
zap_channel_t *zdchan;
};
typedef struct lpwrap_pri lpwrap_pri_t;
......@@ -115,7 +115,7 @@ struct lpwrap_pri_event_list {
const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id);
int lpwrap_one_loop(struct lpwrap_pri *spri);
int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug);
int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug);
int lpwrap_run_pri(struct lpwrap_pri *spri);
#endif
......@@ -219,11 +219,16 @@ static zap_status_t zap_span_destroy(zap_span_t *span)
{
zap_status_t status = ZAP_FAIL;
if (zap_test_flag(span, ZAP_SPAN_CONFIGURED) && span->zio && span->zio->span_destroy) {
zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type);
status = span->zio->span_destroy(span);
zap_safe_free(span->type);
zap_safe_free(span->dtmf_hangup);
if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) {
if (span->stop) {
span->stop(span);
}
if (span->zio && span->zio->span_destroy) {
zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type);
status = span->zio->span_destroy(span);
zap_safe_free(span->type);
zap_safe_free(span->dtmf_hangup);
}
}
return status;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论