comparison mtctest/main.c @ 8:a902ccbf6bbc

mtctest: introduce general user command structure
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 02:48:55 +0000
parents 33d8b3177540
children 395c56969bc4
comparison
equal deleted inserted replaced
7:d0b86b144577 8:a902ccbf6bbc
11 #include <syslog.h> 11 #include <syslog.h>
12 #include <unistd.h> 12 #include <unistd.h>
13 #include <themwi/rtp/rtp_alloc_simple.h> 13 #include <themwi/rtp/rtp_alloc_simple.h>
14 14
15 extern int mtc_socket; 15 extern int mtc_socket;
16 extern int disconnect_mode;
17 extern struct rtp_alloc_simple rtp_info; 16 extern struct rtp_alloc_simple rtp_info;
18 17
19 struct timeval cur_event_time; 18 struct timeval cur_event_time;
20
21 static void
22 drain_stdin()
23 {
24 char buf[256];
25
26 read(0, buf, sizeof buf);
27 }
28 19
29 main(argc, argv) 20 main(argc, argv)
30 char **argv; 21 char **argv;
31 { 22 {
32 extern int optind; 23 extern int optind;
62 max_fd = rtp_info.gsm_rtp_fd; 53 max_fd = rtp_info.gsm_rtp_fd;
63 if (rtp_info.gsm_rtcp_fd > mtc_socket) 54 if (rtp_info.gsm_rtcp_fd > mtc_socket)
64 max_fd = rtp_info.gsm_rtcp_fd; 55 max_fd = rtp_info.gsm_rtcp_fd;
65 for (;;) { 56 for (;;) {
66 FD_ZERO(&fds); 57 FD_ZERO(&fds);
58 FD_SET(0, &fds);
67 FD_SET(mtc_socket, &fds); 59 FD_SET(mtc_socket, &fds);
68 FD_SET(rtp_info.gsm_rtp_fd, &fds); 60 FD_SET(rtp_info.gsm_rtp_fd, &fds);
69 FD_SET(rtp_info.gsm_rtcp_fd, &fds); 61 FD_SET(rtp_info.gsm_rtcp_fd, &fds);
70 if (!disconnect_mode)
71 FD_SET(0, &fds);
72 c = select(max_fd+1, &fds, 0, 0, 0); 62 c = select(max_fd+1, &fds, 0, 0, 0);
73 if (c < 0) { 63 if (c < 0) {
74 if (errno == EINTR) 64 if (errno == EINTR)
75 continue; 65 continue;
76 perror("select"); 66 perror("select");
77 exit(1); 67 exit(1);
78 } 68 }
79 gettimeofday(&cur_event_time, 0); 69 gettimeofday(&cur_event_time, 0);
70 if (FD_ISSET(0, &fds))
71 select_stdin();
80 if (FD_ISSET(mtc_socket, &fds)) 72 if (FD_ISSET(mtc_socket, &fds))
81 mtc_socket_select(); 73 mtc_socket_select();
82 if (!disconnect_mode && FD_ISSET(0, &fds)) {
83 drain_stdin();
84 send_disconnect_req();
85 }
86 if (FD_ISSET(rtp_info.gsm_rtp_fd, &fds)) 74 if (FD_ISSET(rtp_info.gsm_rtp_fd, &fds))
87 rtp_rx_select(); 75 rtp_rx_select();
88 if (FD_ISSET(rtp_info.gsm_rtcp_fd, &fds)) 76 if (FD_ISSET(rtp_info.gsm_rtcp_fd, &fds))
89 rtcp_rx_select(); 77 rtcp_rx_select();
90 } 78 }