From 54309a7b5e7596f79eb1c9915c4bd4ac427f9441 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 12 Dec 2007 14:09:04 +0000 Subject: [PATCH] round port ranges to appropriate values git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6698 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_core_port_allocator.c | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/switch_core_port_allocator.c b/src/switch_core_port_allocator.c index c3e484e386..01f48bd921 100644 --- a/src/switch_core_port_allocator.c +++ b/src/switch_core_port_allocator.c @@ -52,6 +52,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t sta switch_status_t status; switch_memory_pool_t *pool; switch_core_port_allocator_t *alloc; + int even, odd; if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) { return status; @@ -62,15 +63,40 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t sta return SWITCH_STATUS_MEMERR; } - alloc->track_len = (end - start) + 2; alloc->flags = flags; + even = switch_test_flag(alloc, SPF_EVEN); + odd = switch_test_flag(alloc, SPF_ODD); - if (!(switch_test_flag(alloc, SPF_EVEN) && switch_test_flag(alloc, SPF_ODD))) { - alloc->track_len /= 2; + if (!(even && odd)) { + if (even) { + if ((start % 2) != 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding odd start port %d to %d\n", start, start + 1); + start++; + } + if ((end % 2) != 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding odd end port %d to %d\n", end, end - 1); + end--; + } + } else if (odd) { + if ((start % 2) == 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding even start port %d to %d\n", start, start + 1); + start++; + } + if ((end % 2) == 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding even end port %d to %d\n", end, end - 1); + end--; + } + } } - alloc->track = switch_core_alloc(pool, (alloc->track_len + 2) * sizeof(switch_byte_t)); + alloc->track_len = (end - start) + 2; + if (!(even && odd)) { + alloc->track_len /= 2; + } + + alloc->track = switch_core_alloc(pool, (alloc->track_len + 2) * sizeof(switch_byte_t)); + alloc->start = start; alloc->next = start; alloc->end = end;