[Freeswitch-svn] [commit] r7829 - in freeswitch/trunk/src: . include mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Fri Mar 7 13:21:08 EST 2008


Author: anthm
Date: Fri Mar  7 13:21:08 2008
New Revision: 7829

Modified:
   freeswitch/trunk/src/include/switch_rtp.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/switch_rtp.c

Log:
fix rtp break on blocking sockets

Modified: freeswitch/trunk/src/include/switch_rtp.h
==============================================================================
--- freeswitch/trunk/src/include/switch_rtp.h	(original)
+++ freeswitch/trunk/src/include/switch_rtp.h	Fri Mar  7 13:21:08 2008
@@ -191,6 +191,8 @@
 */
 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

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Mar  7 13:21:08 2008
@@ -644,10 +644,10 @@
 	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:

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Fri Mar  7 13:21:08 2008
@@ -1436,7 +1436,7 @@
 				}
 				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 @@
 						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 {

Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c	(original)
+++ freeswitch/trunk/src/switch_rtp.c	Fri Mar  7 13:21:08 2008
@@ -804,14 +804,29 @@
 	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 @@
 		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 @@
 
 			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;



More information about the Freeswitch-svn mailing list