diff options
Diffstat (limited to 'src/transport/test_plugin_transport_wlan_dummy.c')
-rw-r--r-- | src/transport/test_plugin_transport_wlan_dummy.c | 559 |
1 files changed, 281 insertions, 278 deletions
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c index 173d22bba..eba4f9dbd 100644 --- a/src/transport/test_plugin_transport_wlan_dummy.c +++ b/src/transport/test_plugin_transport_wlan_dummy.c | |||
@@ -55,76 +55,79 @@ | |||
55 | static int first; | 55 | static int first; |
56 | 56 | ||
57 | static void | 57 | static void |
58 | sigfunc(int sig) | 58 | sigfunc (int sig) |
59 | { | 59 | { |
60 | closeprog = 1; | 60 | closeprog = 1; |
61 | unlink(FIFO_FILE1); | 61 | unlink (FIFO_FILE1); |
62 | unlink(FIFO_FILE2); | 62 | unlink (FIFO_FILE2); |
63 | } | 63 | } |
64 | 64 | ||
65 | static void | 65 | static void |
66 | stdin_send(void *cls, void *client, | 66 | stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
67 | const struct GNUNET_MessageHeader *hdr) | ||
68 | { | 67 | { |
69 | struct sendbuf *write_pout = cls; | 68 | struct sendbuf *write_pout = cls; |
70 | int sendsize; | 69 | int sendsize; |
71 | struct GNUNET_MessageHeader newheader; | 70 | struct GNUNET_MessageHeader newheader; |
72 | char * to_data; | 71 | char *to_data; |
73 | char * to_radiotap; | 72 | char *to_radiotap; |
74 | char * to_start; | 73 | char *to_start; |
75 | 74 | ||
76 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) | 75 | sendsize = ntohs (hdr->size) - sizeof (struct Radiotap_Send) |
77 | + sizeof(struct Radiotap_rx); | 76 | + sizeof (struct Radiotap_rx); |
78 | 77 | ||
79 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) | 78 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) |
80 | { | 79 | { |
81 | fprintf(stderr, "Function stdin_send: wrong packet type\n"); | 80 | fprintf (stderr, "Function stdin_send: wrong packet type\n"); |
82 | exit(1); | 81 | exit (1); |
83 | } | 82 | } |
84 | if ((sendsize + write_pout->size) > MAXLINE * 2) | 83 | if ((sendsize + write_pout->size) > MAXLINE * 2) |
85 | { | 84 | { |
86 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); | 85 | fprintf (stderr, "Function stdin_send: Packet too big for buffer\n"); |
87 | exit(1); | 86 | exit (1); |
88 | } | 87 | } |
89 | 88 | ||
90 | newheader.size = htons(sendsize); | 89 | newheader.size = htons (sendsize); |
91 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 90 | newheader.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
92 | 91 | ||
93 | to_start = write_pout->buf + write_pout->size; | 92 | to_start = write_pout->buf + write_pout->size; |
94 | memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader)); | 93 | memcpy (to_start, &newheader, sizeof (struct GNUNET_MessageHeader)); |
95 | write_pout->size += sizeof(struct GNUNET_MessageHeader); | 94 | write_pout->size += sizeof (struct GNUNET_MessageHeader); |
96 | 95 | ||
97 | to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader); | 96 | to_radiotap = to_start + sizeof (struct GNUNET_MessageHeader); |
98 | memset(to_radiotap, 0, sizeof (struct Radiotap_rx)); | 97 | memset (to_radiotap, 0, sizeof (struct Radiotap_rx)); |
99 | write_pout->size += sizeof(struct Radiotap_rx); | 98 | write_pout->size += sizeof (struct Radiotap_rx); |
100 | 99 | ||
101 | to_data = to_radiotap + sizeof(struct Radiotap_rx); | 100 | to_data = to_radiotap + sizeof (struct Radiotap_rx); |
102 | memcpy(to_data, | 101 | memcpy (to_data, |
103 | ((char *) hdr) + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), | 102 | ((char *) hdr) + sizeof (struct Radiotap_Send) + |
104 | ntohs(hdr->size) - sizeof(struct Radiotap_Send) - sizeof(struct GNUNET_MessageHeader)); | 103 | sizeof (struct GNUNET_MessageHeader), |
105 | write_pout->size += ntohs(hdr->size) - sizeof(struct Radiotap_Send) - sizeof(struct GNUNET_MessageHeader); | 104 | ntohs (hdr->size) - sizeof (struct Radiotap_Send) - |
105 | sizeof (struct GNUNET_MessageHeader)); | ||
106 | write_pout->size += | ||
107 | ntohs (hdr->size) - sizeof (struct Radiotap_Send) - | ||
108 | sizeof (struct GNUNET_MessageHeader); | ||
106 | } | 109 | } |
107 | 110 | ||
108 | static void | 111 | static void |
109 | file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 112 | file_in_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
110 | { | 113 | { |
111 | struct sendbuf * write_std = cls; | 114 | struct sendbuf *write_std = cls; |
112 | uint16_t sendsize; | 115 | uint16_t sendsize; |
113 | 116 | ||
114 | sendsize = ntohs(hdr->size); | 117 | sendsize = ntohs (hdr->size); |
115 | 118 | ||
116 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) | 119 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) |
117 | { | 120 | { |
118 | fprintf(stderr, "Function file_in_send: wrong packet type\n"); | 121 | fprintf (stderr, "Function file_in_send: wrong packet type\n"); |
119 | exit(1); | 122 | exit (1); |
120 | } | 123 | } |
121 | if ((sendsize + write_std->size) > MAXLINE * 2) | 124 | if ((sendsize + write_std->size) > MAXLINE * 2) |
122 | { | 125 | { |
123 | fprintf(stderr, "Function file_in_send: Packet too big for buffer\n"); | 126 | fprintf (stderr, "Function file_in_send: Packet too big for buffer\n"); |
124 | exit(1); | 127 | exit (1); |
125 | } | 128 | } |
126 | 129 | ||
127 | memcpy(write_std->buf + write_std->size, hdr, sendsize); | 130 | memcpy (write_std->buf + write_std->size, hdr, sendsize); |
128 | write_std->size += sendsize; | 131 | write_std->size += sendsize; |
129 | } | 132 | } |
130 | 133 | ||
@@ -132,7 +135,7 @@ int closeprog; | |||
132 | 135 | ||
133 | 136 | ||
134 | int | 137 | int |
135 | testmode(int argc, char *argv[]) | 138 | testmode (int argc, char *argv[]) |
136 | { | 139 | { |
137 | struct stat st; | 140 | struct stat st; |
138 | int erg; | 141 | int erg; |
@@ -144,111 +147,113 @@ testmode(int argc, char *argv[]) | |||
144 | int fdpout; | 147 | int fdpout; |
145 | 148 | ||
146 | //make the fifos if needed | 149 | //make the fifos if needed |
147 | if (0 != stat(FIFO_FILE1, &st)) | 150 | if (0 != stat (FIFO_FILE1, &st)) |
151 | { | ||
152 | if (0 == stat (FIFO_FILE2, &st)) | ||
148 | { | 153 | { |
149 | if (0 == stat(FIFO_FILE2, &st)) | 154 | fprintf (stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); |
150 | { | 155 | exit (1); |
151 | fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); | 156 | } |
152 | exit(1); | ||
153 | } | ||
154 | |||
155 | umask(0); | ||
156 | //unlink(FIFO_FILE1); | ||
157 | //unlink(FIFO_FILE2); | ||
158 | // FIXME: use mkfifo! | ||
159 | erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); | ||
160 | if (0 != erg) | ||
161 | { | ||
162 | fprintf(stderr, "Error at mknode1 \n"); | ||
163 | //exit(1); | ||
164 | } | ||
165 | erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); | ||
166 | if (0 != erg) | ||
167 | { | ||
168 | fprintf(stderr, "Error at mknode2 \n"); | ||
169 | //exit(1); | ||
170 | } | ||
171 | 157 | ||
158 | umask (0); | ||
159 | //unlink(FIFO_FILE1); | ||
160 | //unlink(FIFO_FILE2); | ||
161 | // FIXME: use mkfifo! | ||
162 | erg = mknod (FIFO_FILE1, S_IFIFO | 0666, 0); | ||
163 | if (0 != erg) | ||
164 | { | ||
165 | fprintf (stderr, "Error at mknode1 \n"); | ||
166 | //exit(1); | ||
172 | } | 167 | } |
173 | else | 168 | erg = mknod (FIFO_FILE2, S_IFIFO | 0666, 0); |
169 | if (0 != erg) | ||
174 | { | 170 | { |
171 | fprintf (stderr, "Error at mknode2 \n"); | ||
172 | //exit(1); | ||
173 | } | ||
175 | 174 | ||
176 | if (0 != stat(FIFO_FILE2, &st)) | 175 | } |
177 | { | 176 | else |
178 | fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); | 177 | { |
179 | exit(1); | ||
180 | } | ||
181 | 178 | ||
179 | if (0 != stat (FIFO_FILE2, &st)) | ||
180 | { | ||
181 | fprintf (stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); | ||
182 | exit (1); | ||
182 | } | 183 | } |
183 | 184 | ||
184 | if (strstr(argv[1], "1")) | 185 | } |
185 | { | ||
186 | //fprintf(stderr, "First\n"); | ||
187 | first = 1; | ||
188 | fpin = fopen(FIFO_FILE1, "r"); | ||
189 | if (NULL == fpin) | ||
190 | { | ||
191 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); | ||
192 | goto end; | ||
193 | } | ||
194 | fpout = fopen(FIFO_FILE2, "w"); | ||
195 | if (NULL == fpout) | ||
196 | { | ||
197 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); | ||
198 | goto end; | ||
199 | } | ||
200 | 186 | ||
187 | if (strstr (argv[1], "1")) | ||
188 | { | ||
189 | //fprintf(stderr, "First\n"); | ||
190 | first = 1; | ||
191 | fpin = fopen (FIFO_FILE1, "r"); | ||
192 | if (NULL == fpin) | ||
193 | { | ||
194 | fprintf (stderr, "fopen of read FIFO_FILE1\n"); | ||
195 | goto end; | ||
201 | } | 196 | } |
202 | else | 197 | fpout = fopen (FIFO_FILE2, "w"); |
198 | if (NULL == fpout) | ||
203 | { | 199 | { |
204 | first = 0; | 200 | fprintf (stderr, "fopen of write FIFO_FILE2\n"); |
205 | //fprintf(stderr, "Second\n"); | 201 | goto end; |
206 | fpout = fopen(FIFO_FILE1, "w"); | ||
207 | if (NULL == fpout) | ||
208 | { | ||
209 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); | ||
210 | goto end; | ||
211 | } | ||
212 | fpin = fopen(FIFO_FILE2, "r"); | ||
213 | if (NULL == fpin) | ||
214 | { | ||
215 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); | ||
216 | goto end; | ||
217 | } | ||
218 | |||
219 | } | 202 | } |
220 | 203 | ||
221 | fdpin = fileno(fpin); | 204 | } |
222 | GNUNET_assert(fpin >= 0); | 205 | else |
223 | 206 | { | |
224 | if (fdpin >= FD_SETSIZE) | 207 | first = 0; |
208 | //fprintf(stderr, "Second\n"); | ||
209 | fpout = fopen (FIFO_FILE1, "w"); | ||
210 | if (NULL == fpout) | ||
225 | { | 211 | { |
226 | fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, | 212 | fprintf (stderr, "fopen of write FIFO_FILE1\n"); |
227 | (unsigned int) FD_SETSIZE); | ||
228 | goto end; | 213 | goto end; |
229 | } | 214 | } |
215 | fpin = fopen (FIFO_FILE2, "r"); | ||
216 | if (NULL == fpin) | ||
217 | { | ||
218 | fprintf (stderr, "fopen of read FIFO_FILE2\n"); | ||
219 | goto end; | ||
220 | } | ||
221 | |||
222 | } | ||
223 | |||
224 | fdpin = fileno (fpin); | ||
225 | GNUNET_assert (fpin >= 0); | ||
226 | |||
227 | if (fdpin >= FD_SETSIZE) | ||
228 | { | ||
229 | fprintf (stderr, "File fdpin number too large (%d > %u)\n", fdpin, | ||
230 | (unsigned int) FD_SETSIZE); | ||
231 | goto end; | ||
232 | } | ||
230 | 233 | ||
231 | fdpout = fileno(fpout); | 234 | fdpout = fileno (fpout); |
232 | GNUNET_assert(fdpout >= 0 ); | 235 | GNUNET_assert (fdpout >= 0); |
233 | 236 | ||
234 | if (fdpout >= FD_SETSIZE) | 237 | if (fdpout >= FD_SETSIZE) |
235 | { | 238 | { |
236 | fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, | 239 | fprintf (stderr, "File fdpout number too large (%d > %u)\n", fdpout, |
237 | (unsigned int) FD_SETSIZE); | 240 | (unsigned int) FD_SETSIZE); |
238 | goto end; | 241 | goto end; |
239 | 242 | ||
240 | } | 243 | } |
241 | 244 | ||
242 | signal(SIGINT, &sigfunc); | 245 | signal (SIGINT, &sigfunc); |
243 | signal(SIGTERM, &sigfunc); | 246 | signal (SIGTERM, &sigfunc); |
244 | 247 | ||
245 | char readbuf[MAXLINE]; | 248 | char readbuf[MAXLINE]; |
246 | int readsize = 0; | 249 | int readsize = 0; |
247 | struct sendbuf write_std; | 250 | struct sendbuf write_std; |
251 | |||
248 | write_std.size = 0; | 252 | write_std.size = 0; |
249 | write_std.pos = 0; | 253 | write_std.pos = 0; |
250 | 254 | ||
251 | struct sendbuf write_pout; | 255 | struct sendbuf write_pout; |
256 | |||
252 | write_pout.size = 0; | 257 | write_pout.size = 0; |
253 | write_pout.pos = 0; | 258 | write_pout.pos = 0; |
254 | 259 | ||
@@ -260,11 +265,11 @@ testmode(int argc, char *argv[]) | |||
260 | struct timeval tv; | 265 | struct timeval tv; |
261 | int retval; | 266 | int retval; |
262 | 267 | ||
263 | struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; | 268 | struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst; |
264 | struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; | 269 | struct GNUNET_SERVER_MessageStreamTokenizer *file_in_mst; |
265 | 270 | ||
266 | stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); | 271 | stdin_mst = GNUNET_SERVER_mst_create (&stdin_send, &write_pout); |
267 | file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std); | 272 | file_in_mst = GNUNET_SERVER_mst_create (&file_in_send, &write_std); |
268 | 273 | ||
269 | //send mac first | 274 | //send mac first |
270 | 275 | ||
@@ -275,187 +280,185 @@ testmode(int argc, char *argv[]) | |||
275 | macaddr.mac[1] = 0x22; | 280 | macaddr.mac[1] = 0x22; |
276 | macaddr.mac[2] = 0x33; | 281 | macaddr.mac[2] = 0x33; |
277 | macaddr.mac[3] = 0x44; | 282 | macaddr.mac[3] = 0x44; |
278 | macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); | 283 | macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256); |
279 | macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); | 284 | macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256); |
280 | 285 | ||
281 | write_std.size = send_mac_to_plugin(write_std.buf, macaddr.mac); | 286 | write_std.size = send_mac_to_plugin (write_std.buf, macaddr.mac); |
282 | 287 | ||
283 | while (0 == closeprog) | 288 | while (0 == closeprog) |
284 | { | 289 | { |
285 | |||
286 | maxfd = 0; | ||
287 | 290 | ||
288 | //set timeout | 291 | maxfd = 0; |
289 | tv.tv_sec = 5; | ||
290 | tv.tv_usec = 0; | ||
291 | 292 | ||
292 | FD_ZERO(&rfds); | 293 | //set timeout |
293 | // if output queue is empty | 294 | tv.tv_sec = 5; |
294 | if (0 == write_pout.size) | 295 | tv.tv_usec = 0; |
295 | { | ||
296 | FD_SET(STDIN_FILENO, &rfds); | ||
297 | 296 | ||
298 | } | 297 | FD_ZERO (&rfds); |
299 | if (0 == write_std.size) | 298 | // if output queue is empty |
300 | { | 299 | if (0 == write_pout.size) |
301 | FD_SET(fdpin, &rfds); | 300 | { |
302 | maxfd = fdpin; | 301 | FD_SET (STDIN_FILENO, &rfds); |
303 | } | ||
304 | FD_ZERO(&wfds); | ||
305 | // if there is something to write | ||
306 | if (0 < write_std.size) | ||
307 | { | ||
308 | FD_SET(STDOUT_FILENO, &wfds); | ||
309 | maxfd = MAX(maxfd, STDOUT_FILENO); | ||
310 | } | ||
311 | 302 | ||
312 | if (0 < write_pout.size) | 303 | } |
313 | { | 304 | if (0 == write_std.size) |
314 | FD_SET(fdpout, &wfds); | 305 | { |
315 | maxfd = MAX(maxfd, fdpout); | 306 | FD_SET (fdpin, &rfds); |
316 | } | 307 | maxfd = fdpin; |
308 | } | ||
309 | FD_ZERO (&wfds); | ||
310 | // if there is something to write | ||
311 | if (0 < write_std.size) | ||
312 | { | ||
313 | FD_SET (STDOUT_FILENO, &wfds); | ||
314 | maxfd = MAX (maxfd, STDOUT_FILENO); | ||
315 | } | ||
317 | 316 | ||
318 | retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); | 317 | if (0 < write_pout.size) |
318 | { | ||
319 | FD_SET (fdpout, &wfds); | ||
320 | maxfd = MAX (maxfd, fdpout); | ||
321 | } | ||
319 | 322 | ||
320 | if (-1 == retval && EINTR == errno) | 323 | retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv); |
321 | { | ||
322 | continue; | ||
323 | } | ||
324 | if (0 > retval) | ||
325 | { | ||
326 | fprintf(stderr, "select failed: %s\n", strerror(errno)); | ||
327 | closeprog = 1; | ||
328 | break; | ||
329 | } | ||
330 | 324 | ||
331 | if (FD_ISSET(STDOUT_FILENO, &wfds)) | 325 | if (-1 == retval && EINTR == errno) |
332 | { | 326 | { |
333 | ret = write(STDOUT_FILENO, | 327 | continue; |
334 | write_std.buf + write_std.pos, | 328 | } |
335 | write_std.size - write_std.pos); | 329 | if (0 > retval) |
336 | if (0 > ret) | 330 | { |
337 | { | 331 | fprintf (stderr, "select failed: %s\n", strerror (errno)); |
338 | closeprog = 1; | 332 | closeprog = 1; |
339 | fprintf(stderr, "Write ERROR to STDOUT\n"); | 333 | break; |
340 | break; | 334 | } |
341 | } | ||
342 | else | ||
343 | { | ||
344 | write_std.pos += ret; | ||
345 | // check if finished | ||
346 | if (write_std.pos == write_std.size) | ||
347 | { | ||
348 | write_std.pos = 0; | ||
349 | write_std.size = 0; | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | 335 | ||
354 | if (FD_ISSET(fdpout, &wfds)) | 336 | if (FD_ISSET (STDOUT_FILENO, &wfds)) |
337 | { | ||
338 | ret = write (STDOUT_FILENO, | ||
339 | write_std.buf + write_std.pos, | ||
340 | write_std.size - write_std.pos); | ||
341 | if (0 > ret) | ||
342 | { | ||
343 | closeprog = 1; | ||
344 | fprintf (stderr, "Write ERROR to STDOUT\n"); | ||
345 | break; | ||
346 | } | ||
347 | else | ||
348 | { | ||
349 | write_std.pos += ret; | ||
350 | // check if finished | ||
351 | if (write_std.pos == write_std.size) | ||
355 | { | 352 | { |
356 | ret = write(fdpout, | 353 | write_std.pos = 0; |
357 | write_pout.buf + write_pout.pos, | 354 | write_std.size = 0; |
358 | write_pout.size - write_pout.pos); | ||
359 | |||
360 | if (0 > ret) | ||
361 | { | ||
362 | closeprog = 1; | ||
363 | fprintf(stderr, "Write ERROR to fdpout\n"); | ||
364 | } | ||
365 | else | ||
366 | { | ||
367 | write_pout.pos += ret; | ||
368 | // check if finished | ||
369 | if (write_pout.pos == write_pout.size) | ||
370 | { | ||
371 | write_pout.pos = 0; | ||
372 | write_pout.size = 0; | ||
373 | } | ||
374 | } | ||
375 | } | 355 | } |
356 | } | ||
357 | } | ||
376 | 358 | ||
377 | if (FD_ISSET(STDIN_FILENO, &rfds)) | 359 | if (FD_ISSET (fdpout, &wfds)) |
360 | { | ||
361 | ret = write (fdpout, | ||
362 | write_pout.buf + write_pout.pos, | ||
363 | write_pout.size - write_pout.pos); | ||
364 | |||
365 | if (0 > ret) | ||
366 | { | ||
367 | closeprog = 1; | ||
368 | fprintf (stderr, "Write ERROR to fdpout\n"); | ||
369 | } | ||
370 | else | ||
371 | { | ||
372 | write_pout.pos += ret; | ||
373 | // check if finished | ||
374 | if (write_pout.pos == write_pout.size) | ||
378 | { | 375 | { |
379 | readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); | 376 | write_pout.pos = 0; |
380 | 377 | write_pout.size = 0; | |
381 | if (0 > readsize) | ||
382 | { | ||
383 | closeprog = 1; | ||
384 | fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); | ||
385 | } | ||
386 | else if (0 < readsize) | ||
387 | { | ||
388 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, | ||
389 | GNUNET_NO, GNUNET_NO); | ||
390 | |||
391 | } | ||
392 | else | ||
393 | { | ||
394 | //eof | ||
395 | closeprog = 1; | ||
396 | } | ||
397 | } | 378 | } |
379 | } | ||
380 | } | ||
398 | 381 | ||
399 | if (FD_ISSET(fdpin, &rfds)) | 382 | if (FD_ISSET (STDIN_FILENO, &rfds)) |
400 | { | 383 | { |
401 | readsize = read(fdpin, readbuf, sizeof(readbuf)); | 384 | readsize = read (STDIN_FILENO, readbuf, sizeof (readbuf)); |
402 | 385 | ||
403 | if (0 > readsize) | 386 | if (0 > readsize) |
404 | { | 387 | { |
405 | closeprog = 1; | 388 | closeprog = 1; |
406 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); | 389 | fprintf (stderr, "Read ERROR to STDIN_FILENO\n"); |
407 | break; | 390 | } |
408 | } | 391 | else if (0 < readsize) |
409 | else if (0 < readsize) | 392 | { |
410 | { | 393 | GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, readsize, |
411 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, | 394 | GNUNET_NO, GNUNET_NO); |
412 | GNUNET_NO, GNUNET_NO); | 395 | |
413 | 396 | } | |
414 | } | 397 | else |
415 | else | 398 | { |
416 | { | 399 | //eof |
417 | //eof | 400 | closeprog = 1; |
418 | closeprog = 1; | 401 | } |
419 | } | 402 | } |
420 | } | ||
421 | 403 | ||
404 | if (FD_ISSET (fdpin, &rfds)) | ||
405 | { | ||
406 | readsize = read (fdpin, readbuf, sizeof (readbuf)); | ||
407 | |||
408 | if (0 > readsize) | ||
409 | { | ||
410 | closeprog = 1; | ||
411 | fprintf (stderr, "Read ERROR to fdpin: %s\n", strerror (errno)); | ||
412 | break; | ||
413 | } | ||
414 | else if (0 < readsize) | ||
415 | { | ||
416 | GNUNET_SERVER_mst_receive (file_in_mst, NULL, readbuf, readsize, | ||
417 | GNUNET_NO, GNUNET_NO); | ||
418 | |||
419 | } | ||
420 | else | ||
421 | { | ||
422 | //eof | ||
423 | closeprog = 1; | ||
424 | } | ||
422 | } | 425 | } |
423 | 426 | ||
427 | } | ||
428 | |||
424 | //clean up | 429 | //clean up |
425 | 430 | ||
426 | GNUNET_SERVER_mst_destroy(stdin_mst); | 431 | GNUNET_SERVER_mst_destroy (stdin_mst); |
427 | GNUNET_SERVER_mst_destroy(file_in_mst); | 432 | GNUNET_SERVER_mst_destroy (file_in_mst); |
428 | 433 | ||
429 | end: if (fpout != NULL) | 434 | end:if (fpout != NULL) |
430 | fclose(fpout); | 435 | fclose (fpout); |
431 | if (fpin != NULL) | 436 | if (fpin != NULL) |
432 | fclose(fpin); | 437 | fclose (fpin); |
433 | 438 | ||
434 | if (1 == first) | 439 | if (1 == first) |
435 | { | 440 | { |
436 | unlink(FIFO_FILE1); | 441 | unlink (FIFO_FILE1); |
437 | unlink(FIFO_FILE2); | 442 | unlink (FIFO_FILE2); |
438 | } | 443 | } |
439 | 444 | ||
440 | return (0); | 445 | return (0); |
441 | } | 446 | } |
442 | 447 | ||
443 | int | 448 | int |
444 | main(int argc, char *argv[]) | 449 | main (int argc, char *argv[]) |
445 | { | 450 | { |
446 | if (2 != argc) | 451 | if (2 != argc) |
447 | { | 452 | { |
448 | fprintf (stderr, | 453 | fprintf (stderr, |
449 | "This program must be started with the operating mode as argument.\n"); | 454 | "This program must be started with the operating mode as argument.\n"); |
450 | fprintf (stderr, | 455 | fprintf (stderr, |
451 | "Usage: options\n" | 456 | "Usage: options\n" |
452 | "options:\n" | 457 | "options:\n" |
453 | "1 = first loopback file\n" | 458 | "1 = first loopback file\n" "2 = second loopback file\n" "\n"); |
454 | "2 = second loopback file\n" | 459 | return 1; |
455 | "\n"); | 460 | } |
456 | return 1; | 461 | if (strstr (argv[1], "1") || strstr (argv[1], "2")) |
457 | } | 462 | return testmode (argc, argv); |
458 | if (strstr(argv[1], "1") || strstr(argv[1], "2")) | ||
459 | return testmode(argc, argv); | ||
460 | return 1; | 463 | return 1; |
461 | } | 464 | } |