]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Simplify trunk transmission path and remove potential race (bug #1802)
authorMark Spencer <markster@digium.com>
Mon, 7 Jun 2004 19:48:53 +0000 (19:48 +0000)
committerMark Spencer <markster@digium.com>
Mon, 7 Jun 2004 19:48:53 +0000 (19:48 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3169 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index a2257fe385e45642bf6434eae8f20a01ea11569a..25097ac4a76ee93af83ddb018a9c9db22b041cbe 100755 (executable)
@@ -267,7 +267,6 @@ static struct iax2_trunk_peer {
        struct iax2_trunk_peer *next;
        int trunkerror;
        int calls;
-       int firstcallno;
 } *tpeers = NULL;
 
 static ast_mutex_t tpeerlock = AST_MUTEX_INITIALIZER;
@@ -1177,6 +1176,20 @@ static int handle_error(void)
        return 0;
 }
 
+static int transmit_trunk(struct iax_frame *f, struct sockaddr_in *sin)
+{
+       int res;
+               res = sendto(netsocket, f->data, f->datalen, 0,(struct sockaddr *)sin,
+                                       sizeof(*sin));
+       if (res < 0) {
+               if (option_debug)
+                       ast_log(LOG_DEBUG, "Received error: %s\n", strerror(errno));
+               handle_error();
+       } else
+               res = 0;
+       return res;
+}
+
 static int send_packet(struct iax_frame *f)
 {
        int res;
@@ -2764,8 +2777,6 @@ static int iax2_trunk_queue(struct chan_iax2_pvt *pvt, struct ast_frame *f)
                /* Copy actual trunk data */
                memcpy(ptr, f->data, f->datalen);
                tpeer->trunkdatalen += f->datalen;
-               if (!tpeer->firstcallno)
-                       tpeer->firstcallno = pvt->callno;
                tpeer->calls++;
                ast_mutex_unlock(&tpeer->lock);
        }
@@ -4332,18 +4343,16 @@ static int send_trunk(struct iax2_trunk_peer *tpeer, struct timeval *now)
                fr->retrans = -1;
                fr->transfer = 0;
                /* Any appropriate call will do */
-               fr->callno = tpeer->firstcallno;
                fr->data = fr->afdata;
                fr->datalen = tpeer->trunkdatalen + sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr);
 #if 0
                ast_log(LOG_DEBUG, "Trunking %d calls in %d bytes, ts=%d\n", calls, fr->datalen, ntohl(mth->ts));
 #endif         
-               res = send_packet(fr);
+               res = transmit_trunk(fr, &tpeer->addr);
                calls = tpeer->calls;
                /* Reset transmit trunk side data */
                tpeer->trunkdatalen = 0;
                tpeer->calls = 0;
-               tpeer->firstcallno = 0;
        }
        if (res < 0)
                return res;