diff -urN asterisk-1.4.9.orig/channels/chan_iax2.c asterisk-1.4.9/channels/chan_iax2.c --- asterisk-1.4.9.orig/channels/chan_iax2.c 2007-07-24 12:32:20.000000000 -0400 +++ asterisk-1.4.9/channels/chan_iax2.c 2007-07-30 17:08:11.000000000 -0400 @@ -1933,14 +1933,14 @@ ast_mutex_unlock(&iaxsl[callno]); /* Do not try again */ if (freeme) { - /* Don't attempt delivery, just remove it from the queue */ - AST_LIST_LOCK(&iaxq.queue); - AST_LIST_REMOVE(&iaxq.queue, f, list); - iaxq.count--; - AST_LIST_UNLOCK(&iaxq.queue); - f->retrans = -1; - /* Free the IAX frame */ - iax2_frame_free(f); +// /* Don't attempt delivery, just remove it from the queue */ +// AST_LIST_LOCK(&iaxq.queue); +// AST_LIST_REMOVE(&iaxq.queue, f, list); +// iaxq.count--; +// AST_LIST_UNLOCK(&iaxq.queue); +// f->retrans = -1; +// /* Free the IAX frame */ +// iax2_frame_free(f); } } @@ -5938,13 +5938,18 @@ AST_LIST_TRAVERSE(&iaxq.queue, f, list) { /* Send a copy immediately */ if ((f->callno == callno) && iaxs[f->callno] && - ((unsigned char ) (f->oseqno - last) < 128)) { - send_packet(f); + ((unsigned char)(f->oseqno - last) < 128)) { + if (f->dcallno != iaxs[f->callno]->peercallno ) + { + ast_log(LOG_WARNING, "Callno inconsistency detected: callno=%d, peercallno=%d, f->dcallno=%d, f->retries=%d, f->retrans=%d\n", callno, iaxs[f->callno]->peercallno, f->dcallno, f->retries, f->retrans); + } else if ( f->retries == -1 ) { + ast_log(LOG_WARNING, "NO LONGER retransmitting frame with -1 retries (src %d, dest %d, retrans %d)\n", f->callno, f->dcallno, f->retrans); + } else + send_packet(f); } } AST_LIST_UNLOCK(&iaxq.queue); } - static void __iax2_poke_peer_s(void *data) { struct iax2_peer *peer = data; @@ -8317,9 +8322,23 @@ count = 0; wakeup = -1; AST_LIST_TRAVERSE_SAFE_BEGIN(&iaxq.queue, f, list) { - if (f->sentyet) + if (f->sentyet) { + /* Remove frames marked for cleanup */ + if (f->retries < 0) { + unsigned short callno = f->callno; + /* Attempt to lock the call pvt -- if we fail, try again later */ + if (ast_mutex_trylock(&iaxsl[callno])) { + wakeup = 1; + continue; + } + AST_LIST_REMOVE_CURRENT(&iaxq.queue, list); + iaxq.count--; + iax2_frame_free(f); + ast_mutex_unlock(&iaxsl[callno]); + } continue; - + } + /* Try to lock the pvt, if we can't... don't fret - defer it till later */ if (ast_mutex_trylock(&iaxsl[f->callno])) { wakeup = 1;