]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add more code to free rtp ports
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 20 Dec 2007 15:41:45 +0000 (15:41 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 20 Dec 2007 15:41:45 +0000 (15:41 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6913 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_rtp.h
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/switch_rtp.c

index 67e0f324d39b8a7359c2e25715b610895d5be141..92b5386fd8dbb566fd0fe778fcb756292552590f 100644 (file)
@@ -75,7 +75,7 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port);
   \return the new port to use
 */
 SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip);
-
+SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port);
 /*! 
   \brief create a new RTP session handle
   \param new_rtp_session a poiter to aim at the new session
index 3bd376793fd9bd825da15a38ff504d79d937de78..97b79561f4df9fa76619233d484d5d4697521840 100644 (file)
@@ -687,6 +687,11 @@ static void terminate_session(switch_core_session_t **session, int line, switch_
 
                tech_pvt = switch_core_session_get_private(*session);
 
+               
+               if (tech_pvt->profile->ip && tech_pvt->local_port) {
+                       switch_rtp_release_port(tech_pvt->profile->ip, tech_pvt->local_port);
+               }
+
                if (!switch_core_session_running(*session) && (!tech_pvt || !switch_test_flag(tech_pvt, TFLAG_READY))) {
                        switch_core_session_destroy(session);
                        return;
@@ -1209,6 +1214,10 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
        tech_pvt = switch_core_session_get_private(session);
        switch_assert(tech_pvt != NULL);
 
+       if (tech_pvt->profile->ip && tech_pvt->local_port) {
+               switch_rtp_release_port(tech_pvt->profile->ip, tech_pvt->local_port);
+       }
+
        switch_clear_flag_locked(tech_pvt, TFLAG_IO);
        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
        switch_set_flag_locked(tech_pvt, TFLAG_BYE);
index 3f281bcaf044ddb48691501088239c4e44c2e965..b209ea226a520f8221ce1dd884008ecb7152aa63 100644 (file)
@@ -201,7 +201,10 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
 
        tech_pvt = (private_object_t *) switch_core_session_get_private(session);
        switch_assert(tech_pvt != NULL);
-
+       
+       if (tech_pvt->profile->rtpip && tech_pvt->local_sdp_audio_port) {
+               switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port);
+       }
 
        if (switch_test_flag(tech_pvt, TFLAG_SIP_HOLD)) {
                const char *buuid;
index 170f88142e166c05c963ae5798f93e9d2cc76319..5fd76cc45dab39541975b62604ca65b5ead5aac4 100644 (file)
@@ -316,16 +316,16 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port)
         return END_PORT;
 }
 
-static void release_port(const char *host, switch_port_t port)
+SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port)
 {
        switch_core_port_allocator_t *alloc = NULL;
 
-       if (!host) {
+       if (!ip) {
                return;
        }
 
     switch_mutex_lock(port_lock);
-    if ((alloc = switch_core_hash_find(alloc_hash, host))) {
+    if ((alloc = switch_core_hash_find(alloc_hash, ip))) {
                switch_core_port_allocator_free_port(alloc, port);
        }
        switch_mutex_unlock(port_lock);
@@ -634,7 +634,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host,
                rtp_session->rx_host = switch_core_strdup(rtp_session->pool, rx_host);
                rtp_session->rx_port = rx_port;
        } else {
-               release_port(rx_host, rx_port);
+               switch_rtp_release_port(rx_host, rx_port);
        }
 
        return rtp_session;
@@ -731,7 +731,7 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session)
                switch_core_timer_destroy(&(*rtp_session)->timer);
        }
 
-       release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port);
+       switch_rtp_release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port);
 
        switch_mutex_unlock((*rtp_session)->flag_mutex);
        return;