78 if ((start % 2) != 0) {
87 if ((start % 2) == 0) {
100 if (!(even && odd)) {
106 alloc->
start = start;
113 *new_allocator = alloc;
153 while (alloc->track_used < alloc->track_len) {
158 index = rand() % alloc->track_len;
161 while (alloc->track[index] && tries < alloc->track_len) {
163 if (alloc->track[index] < 0) {
164 alloc->track[index]++;
166 if (++index >= alloc->track_len) {
171 if (tries < alloc->track_len) {
182 r =
test_port(alloc, AF_INET, SOCK_DGRAM, port);
187 r =
test_port(alloc, AF_INET, SOCK_STREAM, port);
192 alloc->track[index] = 1;
197 alloc->track[index] = -4;
225 if (port < alloc->start) {
229 index = port - alloc->start;
231 if (!(even && odd)) {
236 if (alloc->track[index] > 0) {
237 alloc->track[index] = -4;
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
switch_status_t switch_core_port_allocator_new(const char *ip, switch_port_t start, switch_port_t end, switch_port_flag_t flags, switch_core_port_allocator_t **new_allocator)
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_core_port_allocator_request_port(switch_core_port_allocator_t *alloc, switch_port_t *port_ptr)
#define SWITCH_CHANNEL_LOG
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
switch_memory_pool_t * pool
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
void switch_core_port_allocator_destroy(switch_core_port_allocator_t **alloc)
struct switch_runtime runtime
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
#define SWITCH_MUTEX_NESTED
struct apr_sockaddr_t switch_sockaddr_t
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
switch_status_t switch_core_port_allocator_free_port(switch_core_port_allocator_t *alloc, switch_port_t port)
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
struct apr_thread_mutex_t switch_mutex_t
switch_status_t
Common return values.
switch_status_t switch_socket_close(switch_socket_t *sock)
uint32_t switch_port_flag_t
uint32_t port_alloc_flags
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_thread_id_t switch_thread_self(void)
struct apr_socket_t switch_socket_t
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
static switch_bool_t test_port(switch_core_port_allocator_t *alloc, int family, int type, switch_port_t port)