From d00a0fadc2557598d9159496a196380cb52f9074 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 7 Mar 2008 18:21:08 +0000 Subject: [PATCH] fix rtp break on blocking sockets git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7829 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_rtp.h | 2 ++ src/mod/endpoints/mod_sofia/mod_sofia.c | 4 ++-- src/mod/endpoints/mod_sofia/sofia.c | 4 ++-- src/switch_rtp.c | 31 +++++++++++++++++++++---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 4f5627a048..9b110e573a 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -191,6 +191,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s */ SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session); +SWITCH_DECLARE(void) switch_rtp_break(switch_rtp_t *rtp_session); + /*! \brief Test if an RTP session is ready \param rtp_session an RTP session to test diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index ed9b18ae31..3efb6a1651 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -644,10 +644,10 @@ static switch_status_t sofia_kill_channel(switch_core_session_t *session, int si switch (sig) { case SWITCH_SIG_BREAK: if (switch_rtp_ready(tech_pvt->rtp_session)) { - switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK); + switch_rtp_break(tech_pvt->rtp_session); } if (switch_rtp_ready(tech_pvt->video_rtp_session)) { - switch_rtp_set_flag(tech_pvt->video_rtp_session, SWITCH_RTP_FLAG_BREAK); + switch_rtp_break(tech_pvt->rtp_session); } break; case SWITCH_SIG_KILL: diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index d8f3e8abee..2fd10789ed 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1436,7 +1436,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status } if (switch_core_session_receive_message(other_session, &msg) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Other leg is not available\n"); - nua_respond(tech_pvt->nh, 488, "Hangup in progress", TAG_END()); + nua_respond(tech_pvt->nh, 403, "Hangup in progress", TAG_END()); } switch_core_session_rwunlock(other_session); } @@ -1780,7 +1780,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Passing SDP to other leg.\n%s\n", r_sdp); if (switch_core_session_receive_message(other_session, &msg) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Other leg is not available\n"); - nua_respond(tech_pvt->nh, 488, "Hangup in progress", TAG_END()); + nua_respond(tech_pvt->nh, 403, "Hangup in progress", TAG_END()); } switch_core_session_rwunlock(other_session); } else { diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 3b7b098261..dac7540113 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -804,14 +804,29 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(void) switch_rtp_break(switch_rtp_t *rtp_session) +{ + char o = 42; + switch_size_t len = sizeof(o); + + switch_assert(rtp_session != NULL); + switch_mutex_lock(rtp_session->flag_mutex); + if (rtp_session->sock) { + switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); + switch_socket_sendto(rtp_session->sock, rtp_session->local_addr, 0, (void *) &o, &len); + } + switch_mutex_unlock(rtp_session->flag_mutex); +} + SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session) { switch_assert(rtp_session != NULL); switch_mutex_lock(rtp_session->flag_mutex); if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) { switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO); - switch_assert(rtp_session->sock != NULL); - switch_socket_shutdown(rtp_session->sock, SWITCH_SHUTDOWN_READWRITE); + if (rtp_session->sock) { + switch_socket_shutdown(rtp_session->sock, SWITCH_SHUTDOWN_READWRITE); + } } switch_mutex_unlock(rtp_session->flag_mutex); } @@ -1081,6 +1096,13 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes); + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) { + switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); + bytes = 0; + do_cng = 1; + goto cng; + } + if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) { /* Fast PASS! */ *flags |= SFF_PROXY_PACKET; @@ -1224,10 +1246,9 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ do_cng = 1; } - - if (do_cng || (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK))) { - switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); + cng: + if (do_cng) { memset(&rtp_session->recv_msg.body, 0, 2); rtp_session->recv_msg.body[0] = 127; rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;