68
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <unistd.h>
|
|
5 #include <pthread.h>
|
|
6 #include <arpa/inet.h>
|
|
7
|
|
8 #include "lindaapi.h"
|
|
9
|
|
10 #define PORT 10000
|
|
11
|
|
12 void
|
73
|
13 mainLoop(unsigned int tid, int read_id, FILE* out)
|
68
|
14 {
|
73
|
15 unsigned int rd_seq;
|
|
16 unsigned char *tuple, *data;
|
68
|
17 int len;
|
|
18
|
|
19 /* すでにデータが書き込まれた状態で動くこと */
|
|
20 rd_seq = psx_rd(tid, read_id);
|
|
21 psx_sync_n();
|
|
22
|
|
23 while (1) {
|
|
24 int count;
|
|
25 tuple = psx_reply(rd_seq);
|
|
26 if (tuple) {
|
|
27 len = psx_get_datalength(tuple);
|
|
28 data = tuple+LINDA_HEADER_SIZE;
|
|
29
|
|
30 count=0;
|
|
31 while (count<len) {
|
|
32 count += fwrite(data+count, 1, len-count, out);
|
|
33 }
|
|
34 free(tuple);
|
|
35 break;
|
|
36
|
|
37 }
|
|
38 usleep(500000);
|
|
39 }
|
|
40
|
|
41 return;
|
|
42 }
|
|
43
|
|
44
|
|
45 int
|
|
46 main(int argc, char *argv[]) {
|
|
47 int len = 0;
|
|
48 int tspace;
|
|
49
|
|
50 init_linda();
|
|
51 tspace = open_linda_java("localhost", PORT);
|
|
52 //printf("open socket (tupple space id) = %d\n", tspace);
|
|
53
|
|
54 mainLoop(tspace, 10, stdout);
|
|
55
|
|
56 //printf("mainLoop finished\n");
|
|
57 exit(EXIT_SUCCESS);
|
|
58 }
|
|
59
|
|
60
|