freetdm: OPENZAP-135 -- resolve infinite loop when all channels busy and hunt in round robin mode

This commit is contained in:
Moises Silva 2011-06-15 16:04:35 -04:00
parent b2c3199f65
commit 441c5034f1
1 changed files with 10 additions and 4 deletions

View File

@ -1549,6 +1549,7 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
int best_rate = 0; int best_rate = 0;
uint32_t i = 0; uint32_t i = 0;
uint32_t count = 0; uint32_t count = 0;
uint32_t first_channel = 0;
if (group_id) { if (group_id) {
ftdm_group_find(group_id, &group); ftdm_group_find(group_id, &group);
@ -1573,6 +1574,7 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
i = 0; i = 0;
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) { } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
i = rr_next(group->last_used_index, 0, group->chan_count - 1, direction); i = rr_next(group->last_used_index, 0, group->chan_count - 1, direction);
first_channel = i;
} else { } else {
i = group->chan_count-1; i = group->chan_count-1;
} }
@ -1605,6 +1607,9 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
group->last_used_index = i; group->last_used_index = i;
} }
i = rr_next(i, 0, group->chan_count - 1, direction); i = rr_next(i, 0, group->chan_count - 1, direction);
if (first_channel == i) {
break;
}
} else { } else {
if (i == 0) { if (i == 0) {
break; break;
@ -1663,6 +1668,7 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
int best_rate = 0; int best_rate = 0;
uint32_t i = 0; uint32_t i = 0;
uint32_t count = 0; uint32_t count = 0;
uint32_t first_channel = 0;
*ftdmchan = NULL; *ftdmchan = NULL;
@ -1696,6 +1702,7 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
i = 1; i = 1;
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) { } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
i = rr_next(span->last_used_index, 1, span->chan_count, direction); i = rr_next(span->last_used_index, 1, span->chan_count, direction);
first_channel = i;
} else { } else {
i = span->chan_count; i = span->chan_count;
} }
@ -1706,10 +1713,6 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
if (i > span->chan_count) { if (i > span->chan_count) {
break; break;
} }
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
if (i == span->last_used_index) {
break;
}
} else { } else {
if (i == 0) { if (i == 0) {
break; break;
@ -1738,6 +1741,9 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
span->last_used_index = i; span->last_used_index = i;
} }
i = rr_next(i, 1, span->chan_count, direction); i = rr_next(i, 1, span->chan_count, direction);
if (first_channel == i) {
break;
}
} else { } else {
i--; i--;
} }