add more code to free rtp ports

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6913 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-12-20 15:41:45 +00:00
parent 69b726ec1b
commit 36d84006eb
4 changed files with 19 additions and 7 deletions

View 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

View 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);

View 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;

View 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;