comparison 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
comparison
equal deleted inserted replaced
67:15c9e1f8f756 68:709b78a4ebf0
10 #include <string.h> 10 #include <string.h>
11 #include <strings.h> 11 #include <strings.h>
12 #include <signal.h> 12 #include <signal.h>
13 #include <syslog.h> 13 #include <syslog.h>
14 #include <unistd.h> 14 #include <unistd.h>
15
16 extern unsigned cfg_retrans_timeout;
15 17
16 extern int mgw_socket, sip_socket; 18 extern int mgw_socket, sip_socket;
17 extern int gsm_socket, gsm_is_connected; 19 extern int gsm_socket, gsm_is_connected;
18 20
19 static int max_fd; 21 static int max_fd;
28 30
29 main(argc, argv) 31 main(argc, argv)
30 char **argv; 32 char **argv;
31 { 33 {
32 fd_set fds; 34 fd_set fds;
33 int rc; 35 int rc, need_retrans;
36 struct timeval timeout;
34 37
35 openlog("themwi-sip-in", 0, LOG_LOCAL5); 38 openlog("themwi-sip-in", 0, LOG_LOCAL5);
36 read_config_file(); 39 read_config_file();
37 if (read_number_db() < 0) { 40 if (read_number_db() < 0) {
38 fprintf(stderr, "error reading number database\n"); 41 fprintf(stderr, "error reading number database\n");
57 FD_ZERO(&fds); 60 FD_ZERO(&fds);
58 FD_SET(mgw_socket, &fds); 61 FD_SET(mgw_socket, &fds);
59 FD_SET(sip_socket, &fds); 62 FD_SET(sip_socket, &fds);
60 if (gsm_is_connected) 63 if (gsm_is_connected)
61 FD_SET(gsm_socket, &fds); 64 FD_SET(gsm_socket, &fds);
62 rc = select(max_fd+1, &fds, 0, 0, 0); 65 need_retrans = 0;
66 scan_call_list_for_timeouts(&need_retrans);
67 if (need_retrans) {
68 timeout.tv_sec = cfg_retrans_timeout / 1000;
69 timeout.tv_usec = (cfg_retrans_timeout % 1000) * 1000;
70 rc = select(max_fd+1, &fds, 0, 0, &timeout);
71 } else
72 rc = select(max_fd+1, &fds, 0, 0, 0);
63 if (rc < 0) { 73 if (rc < 0) {
64 if (errno == EINTR) 74 if (errno == EINTR)
65 continue; 75 continue;
66 syslog(LOG_CRIT, "select: %m"); 76 syslog(LOG_CRIT, "select: %m");
67 exit(1); 77 exit(1);
68 } 78 }
69 gettimeofday(&cur_event_time, 0); 79 gettimeofday(&cur_event_time, 0);
80 if (rc == 0) {
81 run_periodic_retrans();
82 continue;
83 }
70 if (gsm_is_connected && FD_ISSET(gsm_socket, &fds)) 84 if (gsm_is_connected && FD_ISSET(gsm_socket, &fds))
71 gsm_socket_select(); 85 gsm_socket_select();
72 if (FD_ISSET(sip_socket, &fds)) 86 if (FD_ISSET(sip_socket, &fds))
73 sip_socket_select(); 87 sip_socket_select();
74 if (FD_ISSET(mgw_socket, &fds)) 88 if (FD_ISSET(mgw_socket, &fds))