FreeCalypso > hg > themwi-system-sw
comparison mgw/main.c @ 170:a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 20 Nov 2022 01:58:47 -0800 |
parents | f062c32a5116 |
children |
comparison
equal
deleted
inserted
replaced
169:648a64b2e16b | 170:a6eb2de277f6 |
---|---|
12 #include <strings.h> | 12 #include <strings.h> |
13 #include <signal.h> | 13 #include <signal.h> |
14 #include <syslog.h> | 14 #include <syslog.h> |
15 #include <unistd.h> | 15 #include <unistd.h> |
16 | 16 |
17 extern int dtmf_timer_running; | |
18 extern struct timeval dtmf_next_time; | |
19 | |
20 fd_set select_for_read; | 17 fd_set select_for_read; |
21 void (*select_handlers[FD_SETSIZE])(); | 18 void (*select_handlers[FD_SETSIZE])(); |
22 void *select_data[FD_SETSIZE]; | 19 void *select_data[FD_SETSIZE]; |
23 struct timeval cur_event_time; | |
24 | 20 |
25 static int max_fd; | 21 static int max_fd; |
26 | 22 |
27 update_max_fd(newfd) | 23 update_max_fd(newfd) |
28 { | 24 { |
37 | 33 |
38 main(argc, argv) | 34 main(argc, argv) |
39 char **argv; | 35 char **argv; |
40 { | 36 { |
41 fd_set fds; | 37 fd_set fds; |
42 struct timeval timeout; | |
43 int cc, i; | 38 int cc, i; |
44 | 39 |
45 openlog("themwi-mgw", 0, LOG_LOCAL5); | 40 openlog("themwi-mgw", 0, LOG_LOCAL5); |
46 read_config_file(); | 41 read_config_file(); |
47 dtmf_init_sample_arrays(); | 42 dtmf_init_sample_arrays(); |
51 } | 46 } |
52 signal(SIGPIPE, SIG_IGN); | 47 signal(SIGPIPE, SIG_IGN); |
53 /* main select loop */ | 48 /* main select loop */ |
54 for (;;) { | 49 for (;;) { |
55 bcopy(&select_for_read, &fds, sizeof(fd_set)); | 50 bcopy(&select_for_read, &fds, sizeof(fd_set)); |
56 if (dtmf_timer_running) { | 51 cc = select(max_fd+1, &fds, 0, 0, 0); |
57 if (timercmp(&dtmf_next_time, &cur_event_time, >)) | |
58 timersub(&dtmf_next_time, &cur_event_time, | |
59 &timeout); | |
60 else | |
61 timerclear(&timeout); | |
62 cc = select(max_fd+1, &fds, 0, 0, &timeout); | |
63 } else | |
64 cc = select(max_fd+1, &fds, 0, 0, 0); | |
65 if (cc < 0) { | 52 if (cc < 0) { |
66 if (errno == EINTR) | 53 if (errno == EINTR) |
67 continue; | 54 continue; |
68 syslog(LOG_CRIT, "select: %m"); | 55 syslog(LOG_CRIT, "select: %m"); |
69 exit(1); | 56 exit(1); |
70 } | 57 } |
71 gettimeofday(&cur_event_time, 0); | |
72 for (i = 0; cc && i <= max_fd; i++) { | 58 for (i = 0; cc && i <= max_fd; i++) { |
73 if (FD_ISSET(i, &fds)) { | 59 if (FD_ISSET(i, &fds)) { |
74 select_handlers[i](i, select_data[i]); | 60 select_handlers[i](i, select_data[i]); |
75 cc--; | 61 cc--; |
76 } | 62 } |
77 } | 63 } |
78 if (dtmf_timer_running && | |
79 !timercmp(&cur_event_time, &dtmf_next_time, <)) | |
80 dtmf_timer_process(); | |
81 free_deleted_endpoints(); | 64 free_deleted_endpoints(); |
82 } | 65 } |
83 } | 66 } |