FreeCalypso > hg > themwi-rtp-mgr
comparison rtp-mgr/main.c @ 2:247f4bbde24c
rtp-mgr: daemon ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 27 May 2024 19:42:19 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:560a3765ab30 | 2:247f4bbde24c |
---|---|
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 extern int syslog_facility; | |
18 | |
19 fd_set select_for_read; | |
20 void (*select_handlers[FD_SETSIZE])(); | |
21 void *select_data[FD_SETSIZE]; | |
22 | |
23 static int max_fd; | |
24 | |
25 update_max_fd(newfd) | |
26 { | |
27 if (newfd >= FD_SETSIZE) { | |
28 syslog(LOG_CRIT, "FATAL: file descriptor %d >= FD_SETSIZE", | |
29 newfd); | |
30 exit(1); | |
31 } | |
32 if (newfd > max_fd) | |
33 max_fd = newfd; | |
34 } | |
35 | |
36 main(argc, argv) | |
37 char **argv; | |
38 { | |
39 fd_set fds; | |
40 int cc, i; | |
41 | |
42 read_config_file(); | |
43 openlog("themwi-rtp-mgr", 0, syslog_facility); | |
44 if (create_ctrl_socket() < 0) { | |
45 fprintf(stderr, | |
46 "error creating RTP allocator control socket\n"); | |
47 exit(1); | |
48 } | |
49 signal(SIGPIPE, SIG_IGN); | |
50 /* main select loop */ | |
51 for (;;) { | |
52 bcopy(&select_for_read, &fds, sizeof(fd_set)); | |
53 cc = select(max_fd+1, &fds, 0, 0, 0); | |
54 if (cc < 0) { | |
55 if (errno == EINTR) | |
56 continue; | |
57 syslog(LOG_CRIT, "select: %m"); | |
58 exit(1); | |
59 } | |
60 for (i = 0; cc && i <= max_fd; i++) { | |
61 if (FD_ISSET(i, &fds)) { | |
62 select_handlers[i](i, select_data[i]); | |
63 cc--; | |
64 } | |
65 } | |
66 } | |
67 } |