FreeCalypso > hg > themwi-system-sw
comparison mncc/main.c @ 15:ccc5ab6d8388
first version of themwi-mncc for ThemWi2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 26 Jun 2022 16:31:47 -0800 |
parents | |
children | 2ebad02adbe5 |
comparison
equal
deleted
inserted
replaced
14:aea422af79dd | 15:ccc5ab6d8388 |
---|---|
1 /* | |
2 * Main module for ThemWi MNCC daemon. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/errno.h> | |
7 #include <stdio.h> | |
8 #include <stdint.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include <signal.h> | |
13 #include <syslog.h> | |
14 #include <unistd.h> | |
15 #include "struct.h" | |
16 | |
17 extern int mncc_socket; | |
18 extern int mtcall_listener; | |
19 extern struct socket_conn *mtcall_socket_head; | |
20 | |
21 static int max_fd; | |
22 | |
23 update_max_fd(newfd) | |
24 { | |
25 if (newfd > max_fd) | |
26 max_fd = newfd; | |
27 } | |
28 | |
29 main(argc, argv) | |
30 char **argv; | |
31 { | |
32 fd_set fds; | |
33 struct socket_conn *conn, **connp; | |
34 int c; | |
35 | |
36 openlog("themwi-mncc", 0, LOG_LOCAL5); | |
37 if (read_number_db() < 0) { | |
38 fprintf(stderr, "error reading number database\n"); | |
39 exit(1); | |
40 } | |
41 if (open_mncc_socket() < 0) { | |
42 fprintf(stderr, "error connecting to GSM MNCC socket\n"); | |
43 exit(1); | |
44 } | |
45 if (create_mtcall_socket() < 0) { | |
46 fprintf(stderr, "error creating MT call socket\n"); | |
47 exit(1); | |
48 } | |
49 signal(SIGPIPE, SIG_IGN); | |
50 /* main select loop */ | |
51 for (;;) { | |
52 FD_ZERO(&fds); | |
53 FD_SET(mncc_socket, &fds); | |
54 FD_SET(mtcall_listener, &fds); | |
55 for (connp = &mtcall_socket_head; conn = *connp; ) { | |
56 if (conn->fd < 0) { | |
57 *connp = conn->next; | |
58 free(conn); | |
59 continue; | |
60 } | |
61 FD_SET(conn->fd, &fds); | |
62 connp = &conn->next; | |
63 } | |
64 c = select(max_fd+1, &fds, 0, 0, 0); | |
65 if (c < 0) { | |
66 if (errno == EINTR) | |
67 continue; | |
68 syslog(LOG_CRIT, "select: %m"); | |
69 exit(1); | |
70 } | |
71 if (FD_ISSET(mncc_socket, &fds)) | |
72 mncc_socket_select(); | |
73 if (FD_ISSET(mtcall_listener, &fds)) | |
74 mtsock_accept_handler(); | |
75 for (conn = mtcall_socket_head; conn; conn = conn->next) | |
76 if (FD_ISSET(conn->fd, &fds)) | |
77 extsock_read_select(conn); | |
78 gc_call_list(); | |
79 } | |
80 } |