From 009c41d460f1356c67240ff5ead72376f532a709 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 11 Dec 2010 11:41:19 -0600 Subject: [PATCH] add new function to init an empty switch_sockaddr_t to avoid an unnecessary dns lookup on 0.0.0.0 --- src/include/switch_apr.h | 2 ++ src/switch_apr.c | 12 ++++++++++++ src/switch_rtp.c | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index dc81d1a522..d89a13bb30 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -1110,6 +1110,8 @@ SWITCH_DECLARE(int) switch_sockaddr_equal(const switch_sockaddr_t *sa1, const sw SWITCH_DECLARE(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); +SWITCH_DECLARE(switch_status_t) switch_sockaddr_create(switch_sockaddr_t **sa, switch_memory_pool_t *pool); + /** * Send data over a network. * @param sock The socket to send the data over. diff --git a/src/switch_apr.c b/src/switch_apr.c index dccc37be96..7c027f8c68 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -729,6 +729,18 @@ SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char * return apr_socket_recv(sock, buf, len); } +SWITCH_DECLARE(switch_status_t) switch_sockaddr_create(switch_sockaddr_t **sa, switch_memory_pool_t *pool) +{ + switch_sockaddr_t *new_sa; + + new_sa = apr_pcalloc(pool, sizeof(apr_sockaddr_t)); + switch_assert(new_sa); + new_sa->pool = pool; + memset(new_sa, 0, sizeof(new_sa)); + *sa = new_sa; + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(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) { diff --git a/src/switch_rtp.c b/src/switch_rtp.c index aba14b2d0a..772c2508a0 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1367,9 +1367,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session switch_rtp_set_flag(rtp_session, flags); /* for from address on recvfrom calls */ - switch_sockaddr_info_get(&rtp_session->from_addr, NULL, SWITCH_UNSPEC, 0, 0, pool); + switch_sockaddr_create(&rtp_session->from_addr, pool); + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_ENABLE_RTCP)) { - switch_sockaddr_info_get(&rtp_session->rtcp_from_addr, NULL, SWITCH_UNSPEC, 0, 0, pool); + switch_sockaddr_create(&rtp_session->rtcp_from_addr, pool); } rtp_session->seq = (uint16_t) rand(); rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (uint32_t) switch_epoch_time_now(NULL));