FreeCalypso > hg > freecalypso-sw
comparison rvinterf/lowlevel/rvifmain.c @ 195:549e6cd1e77d
rvinterf: support for socketpair invokation
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 26 Nov 2013 20:23:38 +0000 |
parents | cf8583923dc4 |
children | 2f285f20d617 |
comparison
equal
deleted
inserted
replaced
194:9e4771bf865f | 195:549e6cd1e77d |
---|---|
20 | 20 |
21 extern u_char rxpkt[]; | 21 extern u_char rxpkt[]; |
22 extern size_t rxpkt_len; | 22 extern size_t rxpkt_len; |
23 | 23 |
24 struct client *client_head; | 24 struct client *client_head; |
25 int socketpair_fd; | |
25 | 26 |
26 char *logfname; | 27 char *logfname; |
27 FILE *logF; | 28 FILE *logF; |
28 time_t logtime; | 29 time_t logtime; |
29 int background; | 30 int background, no_output; |
30 int max_fd; | 31 int max_fd; |
31 | 32 |
32 char *socket_pathname = "/tmp/rvinterf_socket"; | 33 char *socket_pathname = "/tmp/rvinterf_socket"; |
33 | 34 |
34 int wakeup_after_sec; | 35 int wakeup_after_sec; |
40 extern int optind; | 41 extern int optind; |
41 int c; | 42 int c; |
42 fd_set fds; | 43 fd_set fds; |
43 struct client *cli, **clip; | 44 struct client *cli, **clip; |
44 | 45 |
45 while ((c = getopt(argc, argv, "bB:d:l:s:w:")) != EOF) | 46 while ((c = getopt(argc, argv, "bB:d:l:ns:S:w:")) != EOF) |
46 switch (c) { | 47 switch (c) { |
47 case 'b': | 48 case 'b': |
48 background++; | 49 background++; |
50 /* FALL THRU */ | |
51 case 'n': | |
52 no_output++; | |
49 continue; | 53 continue; |
50 case 'B': | 54 case 'B': |
51 baudrate_name = optarg; | 55 baudrate_name = optarg; |
52 continue; | 56 continue; |
53 case 'd': | 57 case 'd': |
56 case 'l': | 60 case 'l': |
57 logfname = optarg; | 61 logfname = optarg; |
58 continue; | 62 continue; |
59 case 's': | 63 case 's': |
60 socket_pathname = optarg; | 64 socket_pathname = optarg; |
65 continue; | |
66 case 'S': | |
67 socketpair_fd = atoi(optarg); | |
61 continue; | 68 continue; |
62 case 'w': | 69 case 'w': |
63 wakeup_after_sec = strtoul(optarg, 0, 0); | 70 wakeup_after_sec = strtoul(optarg, 0, 0); |
64 continue; | 71 continue; |
65 case '?': | 72 case '?': |
84 exit(1); | 91 exit(1); |
85 } | 92 } |
86 fprintf(logF, "*** Log of rvinterf session ***\n"); | 93 fprintf(logF, "*** Log of rvinterf session ***\n"); |
87 setlinebuf(logF); | 94 setlinebuf(logF); |
88 } | 95 } |
89 create_listener_socket(); | 96 if (socketpair_fd) |
97 create_socketpair_client(); | |
98 else | |
99 create_listener_socket(); | |
90 if (background) { | 100 if (background) { |
91 c = fork(); | 101 c = fork(); |
92 if (c < 0) { | 102 if (c < 0) { |
93 perror("fork"); | 103 perror("fork"); |
94 exit(1); | 104 exit(1); |
100 } | 110 } |
101 signal(SIGPIPE, SIG_IGN); | 111 signal(SIGPIPE, SIG_IGN); |
102 for (;;) { | 112 for (;;) { |
103 FD_ZERO(&fds); | 113 FD_ZERO(&fds); |
104 FD_SET(target_fd, &fds); | 114 FD_SET(target_fd, &fds); |
105 FD_SET(listener, &fds); | 115 if (listener) |
116 FD_SET(listener, &fds); | |
106 for (clip = &client_head; cli = *clip; ) { | 117 for (clip = &client_head; cli = *clip; ) { |
107 if (cli->rx_state == 2) { | 118 if (cli->rx_state == 2) { |
108 close(cli->fd); | 119 close(cli->fd); |
109 *clip = cli->next; | 120 *clip = cli->next; |
110 free(cli); | 121 free(cli); |
111 continue; | 122 continue; |
112 } | 123 } |
113 FD_SET(cli->fd, &fds); | 124 FD_SET(cli->fd, &fds); |
114 clip = &cli->next; | 125 clip = &cli->next; |
115 } | 126 } |
127 if (socketpair_fd && !client_head) | |
128 exit(0); | |
116 c = select(max_fd+1, &fds, 0, 0, 0); | 129 c = select(max_fd+1, &fds, 0, 0, 0); |
117 time(&logtime); | 130 time(&logtime); |
118 if (c < 0) { | 131 if (c < 0) { |
119 if (errno == EINTR) | 132 if (errno == EINTR) |
120 continue; | 133 continue; |
121 perror("select"); | 134 perror("select"); |
122 exit(1); | 135 exit(1); |
123 } | 136 } |
124 if (FD_ISSET(target_fd, &fds)) | 137 if (FD_ISSET(target_fd, &fds)) |
125 process_serial_rx(); | 138 process_serial_rx(); |
126 if (FD_ISSET(listener, &fds)) | 139 if (listener && FD_ISSET(listener, &fds)) |
127 handle_listener_select(); | 140 handle_listener_select(); |
128 for (cli = client_head; cli; cli = cli->next) | 141 for (cli = client_head; cli; cli = cli->next) |
129 if (FD_ISSET(cli->fd, &fds)) | 142 if (FD_ISSET(cli->fd, &fds)) |
130 handle_client_select(cli); | 143 handle_client_select(cli); |
131 } | 144 } |
135 { | 148 { |
136 switch (rxpkt[0]) { | 149 switch (rxpkt[0]) { |
137 case RVT_RV_HEADER: | 150 case RVT_RV_HEADER: |
138 if (rxpkt_len < 6) | 151 if (rxpkt_len < 6) |
139 goto unknown; | 152 goto unknown; |
140 if (!background || logF) | 153 if (!no_output || logF) |
141 print_rv_trace(); | 154 print_rv_trace(); |
142 if (client_head) | 155 if (client_head) |
143 forward_rv_trace(); | 156 forward_rv_trace(); |
144 return; | 157 return; |
145 case RVT_L1_HEADER: | 158 case RVT_L1_HEADER: |
146 if (!background || logF) | 159 if (!no_output || logF) |
147 print_l1_trace(); | 160 print_l1_trace(); |
148 if (client_head) | 161 if (client_head) |
149 forward_nonrvt_pkt(); | 162 forward_nonrvt_pkt(); |
150 return; | 163 return; |
151 case RVT_L23_HEADER: | 164 case RVT_L23_HEADER: |
152 if (!background || logF) | 165 if (!no_output || logF) |
153 print_g23_trace(); | 166 print_g23_trace(); |
154 if (client_head) | 167 if (client_head) |
155 forward_nonrvt_pkt(); | 168 forward_nonrvt_pkt(); |
156 return; | 169 return; |
157 case RVT_TM_HEADER: | 170 case RVT_TM_HEADER: |
158 if (!background || logF) | 171 if (!no_output || logF) |
159 print_etm_output_raw(); | 172 print_etm_output_raw(); |
160 if (client_head) | 173 if (client_head) |
161 forward_nonrvt_pkt(); | 174 forward_nonrvt_pkt(); |
162 return; | 175 return; |
163 default: | 176 default: |