chan_iax2: Reduce indentation in __attempt_transmit().

* Reduce indentation in __attempt_transmit().

* Don't update the static last error time variable every time in
__schedule_action() and socket_read().
........

Merged revisions 398456 from http://svn.asterisk.org/svn/asterisk/branches/1.8


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@398457 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/61/61/1
Richard Mudgett 12 years ago
parent aa8405923a
commit 6630c560fd

@ -1511,12 +1511,11 @@ static struct iax2_thread *find_idle_thread(void)
#ifdef SCHED_MULTITHREADED #ifdef SCHED_MULTITHREADED
static int __schedule_action(void (*func)(const void *data), const void *data, const char *funcname) static int __schedule_action(void (*func)(const void *data), const void *data, const char *funcname)
{ {
struct iax2_thread *thread = NULL; struct iax2_thread *thread;
static time_t lasterror; static time_t lasterror;
static time_t t; time_t t;
thread = find_idle_thread(); thread = find_idle_thread();
if (thread != NULL) { if (thread != NULL) {
thread->schedfunc = func; thread->schedfunc = func;
thread->scheddata = data; thread->scheddata = data;
@ -1528,9 +1527,10 @@ static int __schedule_action(void (*func)(const void *data), const void *data, c
return 0; return 0;
} }
time(&t); time(&t);
if (t != lasterror) if (t != lasterror) {
ast_debug(1, "Out of idle IAX2 threads for scheduling!\n"); lasterror = t;
lasterror = t; ast_debug(1, "Out of idle IAX2 threads for scheduling! (%s)\n", funcname);
}
return -1; return -1;
} }
@ -3534,42 +3534,49 @@ static void __attempt_transmit(const void *data)
struct iax_frame *f = (struct iax_frame *)data; struct iax_frame *f = (struct iax_frame *)data;
int freeme = 0; int freeme = 0;
int callno = f->callno; int callno = f->callno;
/* Make sure this call is still active */ /* Make sure this call is still active */
if (callno) if (callno)
ast_mutex_lock(&iaxsl[callno]); ast_mutex_lock(&iaxsl[callno]);
if (callno && iaxs[callno]) { if (callno && iaxs[callno]) {
if ((f->retries < 0) /* Already ACK'd */ || if (f->retries < 0) {
(f->retries >= max_retries) /* Too many attempts */) { /* Already ACK'd */
/* Record an error if we've transmitted too many times */ freeme = 1;
if (f->retries >= max_retries) { } else if (f->retries >= max_retries) {
if (f->transfer) { /* Too many attempts. Record an error. */
/* Transfer timeout */ if (f->transfer) {
send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1); /* Transfer timeout */
} else if (f->final) { send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
iax2_destroy(callno); } else if (f->final) {
} else { iax2_destroy(callno);
if (iaxs[callno]->owner) } else {
ast_log(LOG_WARNING, "Max retries exceeded to host %s on %s (type = %d, subclass = %u, ts=%d, seqno=%d)\n", ast_inet_ntoa(iaxs[f->callno]->addr.sin_addr),ast_channel_name(iaxs[f->callno]->owner), f->af.frametype, f->af.subclass.integer, f->ts, f->oseqno); if (iaxs[callno]->owner) {
iaxs[callno]->error = ETIMEDOUT; ast_log(LOG_WARNING, "Max retries exceeded to host %s on %s (type = %d, subclass = %u, ts=%d, seqno=%d)\n",
if (iaxs[callno]->owner) { ast_inet_ntoa(iaxs[f->callno]->addr.sin_addr),
struct ast_frame fr = { AST_FRAME_CONTROL, { AST_CONTROL_HANGUP }, .data.uint32 = AST_CAUSE_DESTINATION_OUT_OF_ORDER }; ast_channel_name(iaxs[f->callno]->owner),
/* Hangup the fd */ f->af.frametype,
iax2_queue_frame(callno, &fr); /* XXX */ f->af.subclass.integer,
/* Remember, owner could disappear */ f->ts,
if (iaxs[callno] && iaxs[callno]->owner) f->oseqno);
ast_channel_hangupcause_set(iaxs[callno]->owner, AST_CAUSE_DESTINATION_OUT_OF_ORDER); }
} else { iaxs[callno]->error = ETIMEDOUT;
if (iaxs[callno]->reg) { if (iaxs[callno]->owner) {
memset(&iaxs[callno]->reg->us, 0, sizeof(iaxs[callno]->reg->us)); struct ast_frame fr = { AST_FRAME_CONTROL, { AST_CONTROL_HANGUP }, .data.uint32 = AST_CAUSE_DESTINATION_OUT_OF_ORDER };
iaxs[callno]->reg->regstate = REG_STATE_TIMEOUT; /* Hangup the fd */
iaxs[callno]->reg->refresh = IAX_DEFAULT_REG_EXPIRE; iax2_queue_frame(callno, &fr); /* XXX */
} /* Remember, owner could disappear */
iax2_destroy(callno); if (iaxs[callno] && iaxs[callno]->owner)
} ast_channel_hangupcause_set(iaxs[callno]->owner, AST_CAUSE_DESTINATION_OUT_OF_ORDER);
} else {
if (iaxs[callno]->reg) {
memset(&iaxs[callno]->reg->us, 0, sizeof(iaxs[callno]->reg->us));
iaxs[callno]->reg->regstate = REG_STATE_TIMEOUT;
iaxs[callno]->reg->refresh = IAX_DEFAULT_REG_EXPIRE;
} }
iax2_destroy(callno);
} }
freeme = 1; }
freeme = 1;
} else { } else {
/* Update it if it needs it */ /* Update it if it needs it */
update_packet(f); update_packet(f);
@ -8738,8 +8745,6 @@ static int expire_registry(const void *data)
return 0; return 0;
} }
static int iax2_poke_peer(struct iax2_peer *peer, int heldcall);
static void reg_source_db(struct iax2_peer *p) static void reg_source_db(struct iax2_peer *p)
{ {
char data[80]; char data[80];
@ -9701,9 +9706,10 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
if (!(thread = find_idle_thread())) { if (!(thread = find_idle_thread())) {
time(&t); time(&t);
if (t != last_errtime) if (t != last_errtime) {
last_errtime = t;
ast_debug(1, "Out of idle IAX2 threads for I/O, pausing!\n"); ast_debug(1, "Out of idle IAX2 threads for I/O, pausing!\n");
last_errtime = t; }
usleep(1); usleep(1);
return 1; return 1;
} }
@ -11689,12 +11695,13 @@ immediatedial:
/* Don't actually pass these frames along */ /* Don't actually pass these frames along */
if ((f.subclass.integer != IAX_COMMAND_ACK) && if ((f.subclass.integer != IAX_COMMAND_ACK) &&
(f.subclass.integer != IAX_COMMAND_TXCNT) && (f.subclass.integer != IAX_COMMAND_TXCNT) &&
(f.subclass.integer != IAX_COMMAND_TXACC) && (f.subclass.integer != IAX_COMMAND_TXACC) &&
(f.subclass.integer != IAX_COMMAND_INVAL) && (f.subclass.integer != IAX_COMMAND_INVAL) &&
(f.subclass.integer != IAX_COMMAND_VNAK)) { (f.subclass.integer != IAX_COMMAND_VNAK)) {
if (iaxs[fr->callno] && iaxs[fr->callno]->aseqno != iaxs[fr->callno]->iseqno) if (iaxs[fr->callno] && iaxs[fr->callno]->aseqno != iaxs[fr->callno]->iseqno) {
send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno); send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
}
} }
ast_mutex_unlock(&iaxsl[fr->callno]); ast_mutex_unlock(&iaxsl[fr->callno]);
return 1; return 1;
@ -11816,8 +11823,9 @@ immediatedial:
/*iaxs[fr->callno]->last = fr->ts; (do it afterwards cos schedule/forward_delivery needs the last ts too)*/ /*iaxs[fr->callno]->last = fr->ts; (do it afterwards cos schedule/forward_delivery needs the last ts too)*/
fr->outoforder = 0; fr->outoforder = 0;
} else { } else {
if (iaxdebug && iaxs[fr->callno]) if (iaxdebug && iaxs[fr->callno]) {
ast_debug(1, "Received out of order packet... (type=%d, subclass %d, ts = %d, last = %d)\n", f.frametype, f.subclass.integer, fr->ts, iaxs[fr->callno]->last); ast_debug(1, "Received out of order packet... (type=%d, subclass %d, ts = %d, last = %d)\n", f.frametype, f.subclass.integer, fr->ts, iaxs[fr->callno]->last);
}
fr->outoforder = -1; fr->outoforder = -1;
} }
fr->cacheable = ((f.frametype == AST_FRAME_VOICE) || (f.frametype == AST_FRAME_VIDEO)); fr->cacheable = ((f.frametype == AST_FRAME_VOICE) || (f.frametype == AST_FRAME_VIDEO));
@ -14280,7 +14288,7 @@ static int iax2_devicestate(const char *data)
return res; return res;
res = AST_DEVICE_UNAVAILABLE; res = AST_DEVICE_UNAVAILABLE;
ast_debug(3, "iax2_devicestate: Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n", ast_debug(3, "Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n",
pds.peer, ast_sockaddr_ipv4(&p->addr), p->defaddr.sin_addr.s_addr, p->maxms, p->lastms); pds.peer, ast_sockaddr_ipv4(&p->addr), p->defaddr.sin_addr.s_addr, p->maxms, p->lastms);
if ((ast_sockaddr_ipv4(&p->addr) || p->defaddr.sin_addr.s_addr) && if ((ast_sockaddr_ipv4(&p->addr) || p->defaddr.sin_addr.s_addr) &&

Loading…
Cancel
Save