FreeCalypso > hg > themwi-rtp-mgr
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtp-mgr/main.c Mon May 27 19:42:19 2024 +0000 @@ -0,0 +1,67 @@ +/* + * Main module for themwi-rtp-mgr. + */ + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <signal.h> +#include <syslog.h> +#include <unistd.h> + +extern int syslog_facility; + +fd_set select_for_read; +void (*select_handlers[FD_SETSIZE])(); +void *select_data[FD_SETSIZE]; + +static int max_fd; + +update_max_fd(newfd) +{ + if (newfd >= FD_SETSIZE) { + syslog(LOG_CRIT, "FATAL: file descriptor %d >= FD_SETSIZE", + newfd); + exit(1); + } + if (newfd > max_fd) + max_fd = newfd; +} + +main(argc, argv) + char **argv; +{ + fd_set fds; + int cc, i; + + read_config_file(); + openlog("themwi-rtp-mgr", 0, syslog_facility); + if (create_ctrl_socket() < 0) { + fprintf(stderr, + "error creating RTP allocator control socket\n"); + exit(1); + } + signal(SIGPIPE, SIG_IGN); + /* main select loop */ + for (;;) { + bcopy(&select_for_read, &fds, sizeof(fd_set)); + cc = select(max_fd+1, &fds, 0, 0, 0); + if (cc < 0) { + if (errno == EINTR) + continue; + syslog(LOG_CRIT, "select: %m"); + exit(1); + } + for (i = 0; cc && i <= max_fd; i++) { + if (FD_ISSET(i, &fds)) { + select_handlers[i](i, select_data[i]); + cc--; + } + } + } +}