comparison rtp-mgr/main.c @ 179:b79d6334f543

themwi-rtp-mgr: RTP port allocation split out of themwi-mgw
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Mar 2023 20:19:14 -0800
parents mgw/main.c@a6eb2de277f6
children
comparison
equal deleted inserted replaced
178:b259e2722485 179:b79d6334f543
1 /*
2 * Main module for themwi-rtp-mgr.
3 */
4
5 #include <sys/types.h>
6 #include <sys/time.h>
7 #include <sys/errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include <signal.h>
14 #include <syslog.h>
15 #include <unistd.h>
16
17 fd_set select_for_read;
18 void (*select_handlers[FD_SETSIZE])();
19 void *select_data[FD_SETSIZE];
20
21 static int max_fd;
22
23 update_max_fd(newfd)
24 {
25 if (newfd >= FD_SETSIZE) {
26 syslog(LOG_CRIT, "FATAL: file descriptor %d >= FD_SETSIZE",
27 newfd);
28 exit(1);
29 }
30 if (newfd > max_fd)
31 max_fd = newfd;
32 }
33
34 main(argc, argv)
35 char **argv;
36 {
37 fd_set fds;
38 int cc, i;
39
40 openlog("themwi-rtp-mgr", 0, LOG_LOCAL5);
41 read_config_file();
42 if (create_ctrl_socket() < 0) {
43 fprintf(stderr,
44 "error creating RTP allocator control socket\n");
45 exit(1);
46 }
47 signal(SIGPIPE, SIG_IGN);
48 /* main select loop */
49 for (;;) {
50 bcopy(&select_for_read, &fds, sizeof(fd_set));
51 cc = select(max_fd+1, &fds, 0, 0, 0);
52 if (cc < 0) {
53 if (errno == EINTR)
54 continue;
55 syslog(LOG_CRIT, "select: %m");
56 exit(1);
57 }
58 for (i = 0; cc && i <= max_fd; i++) {
59 if (FD_ISSET(i, &fds)) {
60 select_handlers[i](i, select_data[i]);
61 cc--;
62 }
63 }
64 }
65 }