]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix rtp break on blocking sockets
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 7 Mar 2008 18:21:08 +0000 (18:21 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 7 Mar 2008 18:21:08 +0000 (18:21 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7829 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 4f5627a0484399c6f142f042a81d4f7aa73d68c4..9b110e573ac4c154cf178dfe26a3de8a6bc5e4e8 100644 (file)
@@ -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
index ed9b18ae31fa56b30264f4b8d2ca5a1670fa1bd1..3efb6a16513594713180f9639b24ad991b0da1fb 100644 (file)
@@ -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:
index d8f3e8abee8bb65f995e9a9da528efb6fd1945c1..2fd10789ed2b8dd742709fa31b98fb0be774d05e 100644 (file)
@@ -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 {
index 3b7b09826152fb78ef3add8a491af32acdbccb9e..dac75401139a04c6907b85dca738e521a746d582 100644 (file)
@@ -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;