comparison sip-in/main.c @ 107:372209628038

sip-in: handle themwi-mgw shutdown without terminating
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 27 Sep 2022 23:45:40 -0800
parents 709b78a4ebf0
children 7a4d4b8d5f04
comparison
equal deleted inserted replaced
106:245dc4837b56 107:372209628038
13 #include <syslog.h> 13 #include <syslog.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 extern unsigned cfg_retrans_timeout; 16 extern unsigned cfg_retrans_timeout;
17 17
18 extern int mgw_socket, sip_socket;
19 extern int gsm_socket, gsm_is_connected; 18 extern int gsm_socket, gsm_is_connected;
19 extern int mgw_socket, mgw_is_connected;
20 extern int sip_socket;
20 21
21 static int max_fd; 22 static int max_fd;
22 23
23 struct timeval cur_event_time; 24 struct timeval cur_event_time;
24 25
39 read_config_file(); 40 read_config_file();
40 if (read_number_db() < 0) { 41 if (read_number_db() < 0) {
41 fprintf(stderr, "error reading number database\n"); 42 fprintf(stderr, "error reading number database\n");
42 exit(1); 43 exit(1);
43 } 44 }
44 if (open_tmgw_socket() < 0) {
45 fprintf(stderr, "error connecting to themwi-mgw socket\n");
46 exit(1);
47 }
48 if (open_sip_udp_socket() < 0) { 45 if (open_sip_udp_socket() < 0) {
49 fprintf(stderr, "error opening SIP UDP socket\n"); 46 fprintf(stderr, "error opening SIP UDP socket\n");
50 exit(1); 47 exit(1);
51 } 48 }
52 if (argv[1]) { 49 if (argv[1]) {
56 } 53 }
57 signal(SIGPIPE, SIG_IGN); 54 signal(SIGPIPE, SIG_IGN);
58 /* main select loop */ 55 /* main select loop */
59 for (;;) { 56 for (;;) {
60 FD_ZERO(&fds); 57 FD_ZERO(&fds);
61 FD_SET(mgw_socket, &fds);
62 FD_SET(sip_socket, &fds); 58 FD_SET(sip_socket, &fds);
63 if (gsm_is_connected) 59 if (gsm_is_connected)
64 FD_SET(gsm_socket, &fds); 60 FD_SET(gsm_socket, &fds);
61 if (mgw_is_connected)
62 FD_SET(mgw_socket, &fds);
65 need_retrans = 0; 63 need_retrans = 0;
66 scan_call_list_for_timeouts(&need_retrans); 64 scan_call_list_for_timeouts(&need_retrans);
67 if (need_retrans) { 65 if (need_retrans) {
68 timeout.tv_sec = cfg_retrans_timeout / 1000; 66 timeout.tv_sec = cfg_retrans_timeout / 1000;
69 timeout.tv_usec = (cfg_retrans_timeout % 1000) * 1000; 67 timeout.tv_usec = (cfg_retrans_timeout % 1000) * 1000;
81 run_periodic_retrans(); 79 run_periodic_retrans();
82 continue; 80 continue;
83 } 81 }
84 if (gsm_is_connected && FD_ISSET(gsm_socket, &fds)) 82 if (gsm_is_connected && FD_ISSET(gsm_socket, &fds))
85 gsm_socket_select(); 83 gsm_socket_select();
84 if (mgw_is_connected && FD_ISSET(mgw_socket, &fds))
85 mgw_socket_select();
86 if (FD_ISSET(sip_socket, &fds)) 86 if (FD_ISSET(sip_socket, &fds))
87 sip_socket_select(); 87 sip_socket_select();
88 if (FD_ISSET(mgw_socket, &fds))
89 mgw_socket_select();
90 } 88 }
91 } 89 }