]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Revert revision 132506, since it occasionally caused IAX2 HANGUP packets not
authorTilghman Lesher <tilghman@meg.abyt.es>
Wed, 12 Nov 2008 18:39:21 +0000 (18:39 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Wed, 12 Nov 2008 18:39:21 +0000 (18:39 +0000)
to be sent, and instead, schedule a task to destroy the iax2 pvt structure
10 seconds later.  This allows the IAX2 HANGUP packet to be queued,
transmitted, and ACKed before the pvt is destroyed.
(closes issue #13645)
 Reported by: dzajro
 Patches:
       20081111__bug13645__3.diff.txt uploaded by Corydon76 (license 14)
 Tested by: vazir
 Reviewed: http://reviewboard.digium.com/r/51/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@156229 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index 1c3838ef88191d3c60ae3677fb4c5b1bc2004160..6d9aa82f05dc78dd5f5aeea5aa344b0b6ce31ce7 100644 (file)
@@ -1341,6 +1341,20 @@ retry:
        }
 }
 
+static int scheduled_destroy(const void *vid)
+{
+       short callno = PTR_TO_CALLNO(vid);
+       ast_mutex_lock(&iaxsl[callno]);
+       if (iaxs[callno]) {
+               if (option_debug) {
+                       ast_log(LOG_DEBUG, "Really destroying %d now...\n", callno);
+               }
+               iax2_destroy(callno);
+       }
+       ast_mutex_unlock(&iaxsl[callno]);
+       return 0;
+}
+
 static void pvt_destructor(void *obj)
 {
        struct chan_iax2_pvt *pvt = obj;
@@ -3426,15 +3440,19 @@ static int iax2_hangup(struct ast_channel *c)
 {
        unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
        struct iax_ie_data ied;
+       int alreadygone;
        memset(&ied, 0, sizeof(ied));
        ast_mutex_lock(&iaxsl[callno]);
        if (callno && iaxs[callno]) {
                if (option_debug)
                        ast_log(LOG_DEBUG, "We're hanging up %s now...\n", c->name);
+               alreadygone = ast_test_flag(iaxs[callno], IAX_ALREADYGONE);
                /* Send the hangup unless we have had a transmission error or are already gone */
                iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, (unsigned char)c->hangupcause);
-               if (!iaxs[callno]->error && !ast_test_flag(iaxs[callno], IAX_ALREADYGONE)) {
-                       send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
+               if (!iaxs[callno]->error && !alreadygone) {
+                       if (send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1)) {
+                               ast_log(LOG_WARNING, "No final packet could be sent for callno %d\n", callno);
+                       }
                        if (!iaxs[callno]) {
                                ast_mutex_unlock(&iaxsl[callno]);
                                return 0;
@@ -3443,10 +3461,12 @@ static int iax2_hangup(struct ast_channel *c)
                /* Explicitly predestroy it */
                iax2_predestroy(callno);
                /* If we were already gone to begin with, destroy us now */
-               if (iaxs[callno]) {
+               if (iaxs[callno] && alreadygone) {
                        if (option_debug)
                                ast_log(LOG_DEBUG, "Really destroying %s now...\n", c->name);
                        iax2_destroy(callno);
+               } else if (iaxs[callno]) {
+                       ast_sched_add(sched, 10000, scheduled_destroy, CALLNO_TO_PTR(callno));
                }
        } else if (c->tech_pvt) {
                /* If this call no longer exists, but the channel still