diff sip-in/main.c @ 68:709b78a4ebf0

sip-in: implement retransmission of INVITE responses
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Sep 2022 21:56:20 -0800
parents 7005d5c535e8
children 372209628038
line wrap: on
line diff
--- a/sip-in/main.c	Sun Sep 18 16:55:01 2022 -0800
+++ b/sip-in/main.c	Sun Sep 18 21:56:20 2022 -0800
@@ -13,6 +13,8 @@
 #include <syslog.h>
 #include <unistd.h>
 
+extern unsigned cfg_retrans_timeout;
+
 extern int mgw_socket, sip_socket;
 extern int gsm_socket, gsm_is_connected;
 
@@ -30,7 +32,8 @@
 	char **argv;
 {
 	fd_set fds;
-	int rc;
+	int rc, need_retrans;
+	struct timeval timeout;
 
 	openlog("themwi-sip-in", 0, LOG_LOCAL5);
 	read_config_file();
@@ -59,7 +62,14 @@
 		FD_SET(sip_socket, &fds);
 		if (gsm_is_connected)
 			FD_SET(gsm_socket, &fds);
-		rc = select(max_fd+1, &fds, 0, 0, 0);
+		need_retrans = 0;
+		scan_call_list_for_timeouts(&need_retrans);
+		if (need_retrans) {
+			timeout.tv_sec = cfg_retrans_timeout / 1000;
+			timeout.tv_usec = (cfg_retrans_timeout % 1000) * 1000;
+			rc = select(max_fd+1, &fds, 0, 0, &timeout);
+		} else
+			rc = select(max_fd+1, &fds, 0, 0, 0);
 		if (rc < 0) {
 			if (errno == EINTR)
 				continue;
@@ -67,6 +77,10 @@
 			exit(1);
 		}
 		gettimeofday(&cur_event_time, 0);
+		if (rc == 0) {
+			run_periodic_retrans();
+			continue;
+		}
 		if (gsm_is_connected && FD_ISSET(gsm_socket, &fds))
 			gsm_socket_select();
 		if (FD_ISSET(sip_socket, &fds))