comparison sip-in/main.c @ 112:6aa63cf4620a

sip-in call clearing: select timeout implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 18:59:55 -0800
parents 7a4d4b8d5f04
children
comparison
equal deleted inserted replaced
111:7a4d4b8d5f04 112:6aa63cf4620a
31 31
32 main(argc, argv) 32 main(argc, argv)
33 char **argv; 33 char **argv;
34 { 34 {
35 fd_set fds; 35 fd_set fds;
36 int rc, need_retrans; 36 int rc, need_retrans, dead_sip_flag;
37 struct timeval timeout; 37 struct timeval timeout;
38 time_t dead_sip_time;
38 39
39 openlog("themwi-sip-in", 0, LOG_LOCAL5); 40 openlog("themwi-sip-in", 0, LOG_LOCAL5);
40 read_config_file(); 41 read_config_file();
41 if (read_number_db() < 0) { 42 if (read_number_db() < 0) {
42 fprintf(stderr, "error reading number database\n"); 43 fprintf(stderr, "error reading number database\n");
58 FD_SET(sip_socket, &fds); 59 FD_SET(sip_socket, &fds);
59 if (gsm_is_connected) 60 if (gsm_is_connected)
60 FD_SET(gsm_socket, &fds); 61 FD_SET(gsm_socket, &fds);
61 if (mgw_is_connected) 62 if (mgw_is_connected)
62 FD_SET(mgw_socket, &fds); 63 FD_SET(mgw_socket, &fds);
63 need_retrans = 0; 64 need_retrans = dead_sip_flag = 0;
64 scan_call_list_for_timeouts(&need_retrans); 65 scan_call_list_for_timeouts(&need_retrans, &dead_sip_flag,
66 &dead_sip_time);
65 if (need_retrans) { 67 if (need_retrans) {
66 timeout.tv_sec = cfg_retrans_timeout / 1000; 68 timeout.tv_sec = cfg_retrans_timeout / 1000;
67 timeout.tv_usec = (cfg_retrans_timeout % 1000) * 1000; 69 timeout.tv_usec = (cfg_retrans_timeout % 1000) * 1000;
70 rc = select(max_fd+1, &fds, 0, 0, &timeout);
71 } else if (dead_sip_flag) {
72 if (cur_event_time.tv_sec >= dead_sip_time)
73 timeout.tv_sec = 0;
74 else
75 timeout.tv_sec =
76 dead_sip_time - cur_event_time.tv_sec;
77 timeout.tv_usec = 0;
68 rc = select(max_fd+1, &fds, 0, 0, &timeout); 78 rc = select(max_fd+1, &fds, 0, 0, &timeout);
69 } else 79 } else
70 rc = select(max_fd+1, &fds, 0, 0, 0); 80 rc = select(max_fd+1, &fds, 0, 0, 0);
71 if (rc < 0) { 81 if (rc < 0) {
72 if (errno == EINTR) 82 if (errno == EINTR)