[Freeswitch-branches] [commit] r1792 - freeswitch/branches/athompson/trunk/src/mod/applications/mod_sleep

Freeswitch SVN athompson at freeswitch.org
Fri Jul 7 23:53:14 EDT 2006


Author: athompson
Date: Fri Jul  7 23:53:14 2006
New Revision: 1792

Modified:
   freeswitch/branches/athompson/trunk/src/mod/applications/mod_sleep/mod_sleep.c

Log:
Rewrite of mod_sleep to read packets/digits off the channel for the requested time instead of just stopping time with a call to sleep.

Modified: freeswitch/branches/athompson/trunk/src/mod/applications/mod_sleep/mod_sleep.c
==============================================================================
--- freeswitch/branches/athompson/trunk/src/mod/applications/mod_sleep/mod_sleep.c	(original)
+++ freeswitch/branches/athompson/trunk/src/mod/applications/mod_sleep/mod_sleep.c	Fri Jul  7 23:53:14 2006
@@ -36,7 +36,12 @@
 static void sleep_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
+	switch_status_t status;
 	char *delay = NULL;
+	unsigned int timeout;
+	switch_time_t maxtime;
+
+	switch_time_t started = switch_time_now();
 	
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
@@ -44,8 +49,23 @@
 	switch_channel_answer(channel);
 
 	delay = switch_core_session_strdup(session, data);
-	/* 1000000 seems to be equiv to 1 second */
-	switch_sleep(atof(delay) * 1000000);
+	maxtime = (atoi(delay) * 1000) + started;
+
+	while(switch_channel_ready(channel)) {
+		switch_frame_t *read_frame;
+
+		if (switch_time_now() >= maxtime) {
+			break;
+		}
+
+		if (switch_channel_has_dtmf(channel)) {
+			char dtmf[128];
+			switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
+		}
+
+		timeout = (unsigned int)((maxtime - switch_time_now()) / 1000);
+		status = switch_core_session_read_frame(session, &read_frame, timeout, 0);
+	}
 }
 
 static const switch_application_interface_t sleep_application_interface = {



More information about the Freeswitch-branches mailing list