Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 168604) +++ channels/chan_iax2.c (working copy) @@ -1122,13 +1122,20 @@ #define schedule_action(func, data) __schedule_action(func, data, __PRETTY_FUNCTION__) #endif -static int iax2_sched_replace(int id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) +static int _iax2_sched_replace(int *id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, const char *func, int line) { - AST_SCHED_REPLACE(id, con, when, callback, data); + int _count = 0; + while (*id > -1 && ast_sched_del(sched, *id) && ++_count < 10) { + usleep(1); + } + if (_count == 10) + ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", *id, __FILE__, func, line); + *id = ast_sched_add_variable(sched, when, callback, data, 0); signal_condition(&sched_lock, &sched_cond); - return id; + return *id; } +#define iax2_sched_replace(a,b,c,d,e) _iax2_sched_replace(&(a),b,c,d,e,__PRETTY_FUNCTION__,__LINE__) static int iax2_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) { @@ -4760,7 +4767,7 @@ frb.fr2.afdatalen = sizeof(frb.buffer); if (!pvt) { - ast_log(LOG_WARNING, "No private structure for packet?\n"); + ast_log(LOG_WARNING, "No private structure for packet? (frametype %d/subtype %d)\n", f->frametype, f->subclass); return -1; } @@ -5769,9 +5776,10 @@ res = 0; else if (!ast_test_flag(&iaxs[callno]->state, IAX_STATE_STARTED)) res = 0; - else + else { /* Simple, just queue for transmission */ res = iax2_send(iaxs[callno], f, 0, -1, 0, 0, 0); + } } else { ast_debug(1, "Write error: %s\n", strerror(errno)); } @@ -5804,7 +5812,12 @@ { int res; ast_mutex_lock(&iaxsl[callno]); - res = send_command(iaxs[callno], type, command, ts, data, datalen, seqno); + if (!iaxs[callno]) { + ast_log(LOG_WARNING, "Call %d no longer exists. Cannot send (type %hhd/cmd %d/ts %u)\n", callno, type, command, ts); + res = -1; + } else { + res = send_command(iaxs[callno], type, command, ts, data, datalen, seqno); + } ast_mutex_unlock(&iaxsl[callno]); return res; }