diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-06-07 19:48:53 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-06-07 19:48:53 +0000 |
commit | a8834cd4cfae9ab3b6f9a44712fd270f2d5ed57e (patch) | |
tree | 7ad2e5a792551a2f8b5d2d84c9b2850678101dfe /channels/chan_iax2.c | |
parent | 3c9ee103b2eccce37e45c79940b94ae10e7f8c5b (diff) |
Simplify trunk transmission path and remove potential race (bug #1802)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3169 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_iax2.c')
-rwxr-xr-x | channels/chan_iax2.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index a2257fe38..25097ac4a 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -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; |