comparison mtctest/main.c @ 5:e7b192a5dee5

mtctest: initial import from old ThemWi
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 00:58:38 +0000
parents
children 33d8b3177540
comparison
equal deleted inserted replaced
4:ce450869db09 5:e7b192a5dee5
1 /*
2 * Main module for ThemWi test MT call generator.
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 <syslog.h>
12 #include <unistd.h>
13
14 extern int mtc_socket;
15 extern int disconnect_mode;
16
17 struct timeval cur_event_time;
18
19 static void
20 drain_stdin()
21 {
22 char buf[256];
23
24 read(0, buf, sizeof buf);
25 }
26
27 main(argc, argv)
28 char **argv;
29 {
30 extern int optind;
31 extern char *optarg;
32 char *from;
33 fd_set fds;
34 int c;
35
36 from = 0;
37 while ((c = getopt(argc, argv, "f:")) != EOF) {
38 switch (c) {
39 case 'f':
40 from = optarg;
41 continue;
42 default:
43 usage:
44 fprintf(stderr,
45 "usage: %s [-f from-number] to-number\n",
46 argv[0]);
47 exit(1);
48 }
49 }
50 if (argc != optind + 1)
51 goto usage;
52 openlog("themwi-test-mtc", 0, LOG_LOCAL5);
53 init_setup_msg(from, argv[optind]);
54 obtain_dummy_rtp();
55 connect_mtc_socket();
56 send_setup_msg();
57 /* main select loop */
58 for (;;) {
59 FD_ZERO(&fds);
60 FD_SET(mtc_socket, &fds);
61 if (!disconnect_mode)
62 FD_SET(0, &fds);
63 c = select(mtc_socket+1, &fds, 0, 0, 0);
64 if (c < 0) {
65 if (errno == EINTR)
66 continue;
67 perror("select");
68 exit(1);
69 }
70 gettimeofday(&cur_event_time, 0);
71 if (FD_ISSET(mtc_socket, &fds))
72 mtc_socket_select();
73 if (!disconnect_mode && FD_ISSET(0, &fds)) {
74 drain_stdin();
75 send_disconnect_req();
76 }
77 }
78 }