comparison mgw/main.c @ 32:b3f74df7b808

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