changeset 68:1b86f7cfb01a

add examples
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Wed, 21 Oct 2009 21:11:43 +0900
parents 264123227f0d
children d86f68912831
files .hgignore examples/filesend/Makefile examples/filesend/deleter.c examples/filesend/reader.c examples/filesend/writer.c examples/readerwriter/Makefile examples/readerwriter/reader.c examples/readerwriter/writer.c tools/Linda_library/Makefile tools/Linda_library/ldserv tools/Linda_library/liblindaapi.a tools/Linda_library/lindaapi.c tools/Linda_library/lindaapi.h
diffstat 13 files changed, 650 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,12 @@
+syntax: glob
+
+*.a
+*.o
+.*.swp
+.*.swo
+GTAGS
+GRTAGS
+GSYMS
+GPATH
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/filesend/Makefile	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,40 @@
+CC=gcc
+CFLAGS=-g -O0
+CPPFLAGS=-I ../../tools/Linda_library
+LIBS=-llindaapi
+LDFLAGS=-L ../../tools/Linda_library
+
+TARGET=reader writer deleter
+
+all: $(TARGET)
+
+.c.o:
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ -o $@
+
+reader: reader.o
+	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
+writer: writer.o
+	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
+deleter: deleter.o
+	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
+
+run-server:
+	java -cp ../../FedLinda.jar fdl.FDLindaServ -port 10000
+
+run-reader: reader
+	./reader
+run-writer: writer
+	./writer
+
+
+clean:
+	rm -rf *.o $(TARGET)
+
+makedata:
+	dd bs=1024 count=500 if=/dev/urandom of=testdata/test500K.dat
+	dd bs=1024 count=1000 if=/dev/urandom of=testdata/test1M.dat
+	dd bs=1024 count=5000 if=/dev/urandom of=testdata/test5M.dat
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/filesend/deleter.c	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include "lindaapi.h"
+
+#define PORT 10000
+
+
+void
+del_callback(unsigned char *data, void *arg)
+{
+	free(data);
+}
+void
+psx_del(int t, int id)
+{
+	psx_callback_in(t, id, del_callback, NULL);
+}
+
+int
+main(int argc, char *argv[]) {
+	int len = 0;
+	int tspace;
+	int id = 10;
+
+	init_linda();
+	tspace = open_linda_java("localhost", PORT);
+	printf("open socket (tupple space id) = %d\n", tspace);
+
+	psx_del(tspace, id);
+
+	printf("mainLoop finished\n");
+	exit(EXIT_SUCCESS);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/filesend/reader.c	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <arpa/inet.h>
+
+#include "lindaapi.h"
+
+#define PORT 10000
+
+void
+mainLoop(int tid, int read_id, FILE* out)
+{
+	int rd_seq;
+	char *tuple, *data;
+	int len;
+
+	/* すでにデータが書き込まれた状態で動くこと  */
+	rd_seq = psx_rd(tid, read_id);
+	psx_sync_n();
+
+	while (1) {
+		int count;
+		tuple = psx_reply(rd_seq);
+		if (tuple) {
+			len = psx_get_datalength(tuple);
+			data = tuple+LINDA_HEADER_SIZE;
+
+			count=0;
+			while (count<len) {
+				count += fwrite(data+count, 1, len-count, out);
+			}
+			free(tuple);
+			break;
+
+		}
+		usleep(500000);
+	}
+
+	return;
+}
+
+
+int
+main(int argc, char *argv[]) {
+	int len = 0;
+	int tspace;
+
+	init_linda();
+	tspace = open_linda_java("localhost", PORT);
+	//printf("open socket (tupple space id) = %d\n", tspace);
+
+	mainLoop(tspace, 10, stdout);
+
+	//printf("mainLoop finished\n");
+	exit(EXIT_SUCCESS);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/filesend/writer.c	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include "lindaapi.h"
+
+#define PORT 10000
+
+
+void
+mainLoop(int tid, int write_id, int fd)
+{
+	void *addr;
+	struct stat sb;
+
+	if (fstat(fd, &sb) == -1) {
+		perror("fstat");
+		exit(1);
+	}
+	addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if (addr==NULL) {
+		perror("mmap");
+		exit(1);
+	}
+
+	printf("file size=%d\n", sb.st_size);
+
+	psx_out(tid, write_id, addr, sb.st_size);
+	psx_sync_n();
+
+
+	return;
+}
+
+
+int
+main(int argc, char *argv[]) {
+	int len = 0;
+	int tspace;
+
+	init_linda();
+	tspace = open_linda_java("localhost", PORT);
+	printf("open socket (tupple space id) = %d\n", tspace);
+
+	mainLoop(tspace, 10, fileno(stdin));
+
+	printf("mainLoop finished\n");
+	exit(EXIT_SUCCESS);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/readerwriter/Makefile	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,28 @@
+CC=gcc
+CFLAGS=-g -O0
+CPPFLAGS=-I ../../tools/Linda_library
+LIBS=-llindaapi
+LDFLAGS=-L ../../tools/Linda_library
+
+
+all: reader writer
+
+.c.o:
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ -o $@
+
+reader: reader.o
+	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
+writer: writer.o
+	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
+
+run-server:
+	java -cp ../../FedLinda.jar fdl.FDLindaServ -port 10000
+
+run-reader: reader
+	./reader
+run-writer: writer
+	./writer
+
+
+clean:
+	rm -rf reader writer *.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/readerwriter/reader.c	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,193 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <arpa/inet.h>
+
+#include "lindaapi.h"
+
+#define PORT 10000
+
+/*
+ *  lindaapiの例題
+ *  writer側で書き込んだ文字列を表示するだけ
+ *
+ *  mainLoop: 
+ *    psx_rdを使った例題
+ *    相手が追加で書き込まなければずっと同じものを読みつづける
+ *
+ *  mainLoop2:
+ *    psx_rdを使った例題
+ *    上と違い、writerが送るフラグをみて、新しいデータだった場合のみ表示
+ *
+ *  mainLoop3:
+ *    psx_wait_rdを使った例題
+ *    ビジーループでもないしフラグを見る必要もないwaitする
+ *
+ *  mainLoop4:
+ *    callback_wait_rdを使った例題
+ *    ループはsyncするだけよ
+ *
+ */
+
+struct callback_arg{
+	int tid;
+	int read_id;
+};
+void
+callbacker(unsigned char *tuple, void *arg) {
+	int len;
+	char *data;
+	struct callback_arg *carg = arg;
+
+	len = psx_get_datalength(tuple);
+	// 最初の4byteデータは使わない
+	data = tuple+LINDA_HEADER_SIZE+4;
+	len -= 4;
+
+	/* dataは'\0'で終わっている事を期待	(writerで保証する)  */
+	printf("get data[%d]: `%s'\n", len, data);
+	free(tuple);
+
+	psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, arg);
+}
+void
+mainLoop4(int tid, int read_id)
+{
+	int rd_seq;
+	char *tuple, *data;
+	int len;
+	struct callback_arg carg = { tid, read_id };
+
+	psx_callback_wait_rd(tid, read_id, callbacker, &carg);
+
+	while (1) {
+		psx_sync_n();
+		usleep(500000);
+	}
+
+	return;
+}
+
+void
+mainLoop3(int tid, int read_id)
+{
+	int rd_seq;
+	char *tuple, *data;
+	int len;
+
+	while (1) {
+		rd_seq = psx_wait_rd(tid, read_id);
+		psx_sync_n();
+
+		while (1) {
+			tuple = psx_reply(rd_seq);
+			if (tuple) {
+				len = psx_get_datalength(tuple);
+				// 最初の4byteデータは使わない
+				data = tuple+LINDA_HEADER_SIZE+4;
+				len -= 4;
+
+				/* dataは'\0'で終わっている事を期待	(writerで保証する)  */
+				printf("get data[%d]: `%s'\n", len, data);
+				free(tuple);
+				break;
+			}
+			psx_sync_n();
+			usleep(500000);
+		}
+	}
+
+	return;
+}
+
+void
+mainLoop2(int tid, int read_id)
+{
+	int rd_seq;
+	char *tuple, *data;
+	int len;
+	uint32_t prev_id=-1;
+
+	while (1) {
+		rd_seq = psx_rd(tid, read_id);
+		psx_sync_n();
+
+		while (1) {
+			tuple = psx_reply(rd_seq);
+			if (tuple) {
+				uint32_t line_id;
+				len = psx_get_datalength(tuple);
+				// 最初の4byteデータは行番号
+				data = tuple+LINDA_HEADER_SIZE+4;
+				len -= 4;
+
+				line_id = ntohl(((uint32_t*)(tuple+LINDA_HEADER_SIZE))[0]);
+				if (prev_id!=line_id) {
+					/* dataは'\0'で終わっている事を期待	(writerで保証する)  */
+					printf("get data[%d]: `%s', line_id=%d\n", len, data, line_id);
+					prev_id = line_id;
+				}
+
+				free(tuple);
+				break;
+			}
+			usleep(500000);
+		}
+	}
+
+	return;
+}
+
+void
+mainLoop(int tid, int read_id)
+{
+	int rd_seq;
+	char *tuple, *data;
+	int len;
+
+	while (1) {
+		rd_seq = psx_rd(tid, read_id);
+		psx_sync_n();
+
+		while (1) {
+			tuple = psx_reply(rd_seq);
+			if (tuple) {
+				len = psx_get_datalength(tuple);
+				// 最初の4byteデータは使わない
+				data = tuple+LINDA_HEADER_SIZE+4;
+				len -= 4;
+
+				/* dataは'\0'で終わっている事を期待	(writerで保証する)  */
+				printf("get data[%d]: `%s'\n", len, data);
+				free(tuple);
+				break;
+			}
+			usleep(500000);
+		}
+	}
+
+	return;
+}
+
+
+int
+main(int argc, char *argv[]) {
+	int len = 0;
+	int tspace;
+
+	init_linda();
+	tspace = open_linda_java("localhost", PORT);
+	printf("open socket (tupple space id) = %d\n", tspace);
+
+	mainLoop4(tspace, 10);
+	//mainLoop3(tspace, 10);
+	//mainLoop2(tspace, 10);
+	//mainLoop(tspace, 10);
+
+	printf("mainLoop finished\n");
+	exit(EXIT_SUCCESS);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/readerwriter/writer.c	Wed Oct 21 21:11:43 2009 +0900
@@ -0,0 +1,86 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <arpa/inet.h>
+
+#include "lindaapi.h"
+
+#define PORT 10000
+
+void
+del_callback(unsigned char *data, void *arg)
+{
+	free(data);
+}
+void
+psx_del(int t, int id)
+{
+	psx_callback_in(t, id, del_callback, NULL);
+}
+
+
+void
+mainLoop(int tid, int write_id)
+{
+	int size=BUFSIZ;
+	char *buff = malloc(size);
+	int len;
+	uint32_t line_id=0;
+
+	if ( (buff=malloc(size))==NULL ) {
+		perror("malloc");
+		exit(EXIT_FAILURE);
+	}
+
+	/* '\0'も含めて送信  */
+	psx_out(tid, write_id, "\0\0\0\0aiueo", 10);
+	psx_sync_n();
+
+	while (1) {
+		char *data = buff+4;
+		/* 標準入力から読み込み、改行を削除  */
+		fgets(data, size-4, stdin);
+		len = strlen(data);
+		if (data[len-1]=='\n') {
+			data[--len] = '\0';
+		}
+		((uint32_t*)buff)[0] = htonl(line_id);
+
+		if (len==size) {
+			/* realloc  */
+		}
+
+		/* まえのデータを消す  */
+		psx_del(tid, write_id);
+		/* '\0'も含めて送信  */
+		psx_out(tid, write_id, (void *)buff, len+4+1);
+
+		psx_sync_n();
+		printf("send data[%d] line_id=%d, `%s'\n", len, line_id, data);
+		printf("line_id =%d\n", ntohl(((uint32_t*)buff)[0]));
+
+		line_id++;
+	}
+
+	return;
+}
+
+
+int
+main(int argc, char *argv[]) {
+	int len = 0;
+	int tspace;
+
+	init_linda();
+	tspace = open_linda_java("localhost", PORT);
+	printf("open socket (tupple space id) = %d\n", tspace);
+
+	mainLoop(tspace, 10);
+
+	printf("mainLoop finished\n");
+	exit(EXIT_SUCCESS);
+}
+
+
--- a/tools/Linda_library/Makefile	Sat Jun 06 14:33:59 2009 +0900
+++ b/tools/Linda_library/Makefile	Wed Oct 21 21:11:43 2009 +0900
@@ -1,7 +1,8 @@
 CC=gcc
 AR=ar
-CFLAGS=-c -g -Wall
-FLAGS=-Wall -DDEBUG
+CFLAGS=-g -O2 -Wall
+#FLAGS=-Wall -DDEBUG
+FLAGS=-Wall
 TARGET=ldserv liblindaapi.a
 LINDADIR=.
 LIBDIR=$(LINDADIR)
@@ -11,9 +12,11 @@
 ldserv : $(LINDADIR)/ldserv.c
 	$(CC) $(FLAGS) -g -o ldserv $(LINDADIR)/ldserv.c
 
-liblindaapi.a : $(LINDADIR)/lindaapi.c
-	$(CC) $(FLAGS) -g -c -o lindaapi.o $(LINDADIR)/lindaapi.c
-	$(AR) cr $(LIBDIR)/liblindaapi.a lindaapi.o
+.c.o:
+	$(CC) $(CFLAGS) -c $^ -o $@
+
+liblindaapi.a : lindaapi.o
+	$(AR) crus $@ $^
 
 clean :
 	rm -f $(TARGET) *.o
Binary file tools/Linda_library/ldserv has changed
Binary file tools/Linda_library/liblindaapi.a has changed
--- a/tools/Linda_library/lindaapi.c	Sat Jun 06 14:33:59 2009 +0900
+++ b/tools/Linda_library/lindaapi.c	Wed Oct 21 21:11:43 2009 +0900
@@ -2,7 +2,7 @@
 //
 
 /*----------------------------------------------------------------------
- 󥯥롼ɥեɤ߹
+ インクルードファイル読み込み
 ----------------------------------------------------------------------*/
 #include <stdio.h>
 #include <string.h>
@@ -32,11 +32,11 @@
 #endif
 
 /* Global Variables */
-static COMMAND *q_top, *q_end; /* ޥɥ塼 */
-static REPLY *reply, *r_end;   /* ѥ塼 */
-static int qsize; /* ޥɥ塼Υ */
-static fd_set g_fds;   /* ³Ƥ륿ץ륹ڡFD(FileDiscripter)ݻ */
-static unsigned int g_max_fds;  /* ƻ뤹FDκ */
+static COMMAND *q_top, *q_end; /* コマンドキュー */
+static REPLY *reply, *r_end;   /* 受け取り用キュー */
+static int qsize; /* コマンドキューのサイズ */
+static fd_set g_fds;   /* 接続しているタプルスペース群のFD(FileDiscripter)を保持 */
+static unsigned int g_max_fds;  /* 監視するFDの最大値 */
 
 /* Static Functions */
 static void unix_chkserv(int ps);
@@ -53,10 +53,10 @@
 /*-------------------------------------------------------------------/
   static void
   count_packet (char type):
-      ѥåȤȤ
+      パケットの送受信カウントする
       
-  :
-      type -  (char: s,r)
+  引き数:
+      type - 送信、受信 (char型: s,r)
 /-------------------------------------------------------------------*/
 static void
 count_packet(char type)
@@ -98,17 +98,17 @@
 /*-------------------------------------------------------------------/
   static int
   unix_write (int fd, unsigned char *buf, unsigned int size):
-      ФTUPLE롣
+      サーバへTUPLEを送る。
 
-  :
-      fd   - ФΥեǥץ
-      buf  - Фǡ(TUPLEإåޤ)
-      size - bufbyte
-  ֤:
-      ä(񤭤)ǡbyte
+  引き数:
+      fd   - サーバのファイルディスクリプタ
+      buf  - サーバへ送るデータ(TUPLEヘッダ含む)
+      size - bufのbyte数
+  返り値:
+      送った(書きこんだ)データのbyte数
 /-------------------------------------------------------------------*/
 static int
-unix_write(int fd,unsigned char *buf,unsigned int size) {
+unix_write_bak(int fd,unsigned char *buf,unsigned int size) {
     int i,nsize;
     nsize = htonl(size);
     i  = write(fd,&nsize,INT_SIZE);
@@ -118,6 +118,24 @@
 #endif
     return(i);
 }
+static int
+unix_write(int fd,unsigned char *buf,unsigned int size) {
+    int count=0;
+    uint32_t nsize;
+
+    /* これから送信するデータのサイズをまず送信  */
+    nsize = htonl(size);
+    write(fd, &nsize, INT_SIZE);
+
+    /* 目的のデータを送信  */
+    while (count < size) {
+	count += write(fd, buf+count, size-count);
+    }
+#ifdef COUNT_PACKET
+    count_packet('s');
+#endif
+    return count+INT_SIZE;
+}
 
 #define unix_write_w   unix_write
 
@@ -131,12 +149,12 @@
 /*-------------------------------------------------------------------/
   void
   init_linda():
-      ѿνԤʤ
+      大域変数の初期化等を行なう
 /-------------------------------------------------------------------*/
 void
 init_linda() {
     FD_ZERO(&g_fds);
-    /* ѿϥꥢ
+    /* 大域変数はゼロクリアされる
     g_max_fds = 0;
     q_end = q_top = NULL;
     r_end = reply = NULL;
@@ -148,15 +166,15 @@
 /*-------------------------------------------------------------------/
   int
   open_linda (char * hostname, int port):
-      LindaФȤΥͥΩץ륹ڡID֤
-      ߤϥեǥץ֤Ƥ롣
+      Lindaサーバとのコネクションを確立し、タプルスペースのIDを返す。
+      現在はファイルディスクリプタを返している。
 
-  :
-      hostname - ФΥۥ̾
-      port - ФΥݡֹ
-  ֤:
-      ͥΩȤΥեǥץ֤
-      Ԥ -1 ֤
+  引き数:
+      hostname - サーバのホスト名
+      port - サーバのポート番号
+  返り値:
+      コネクション確立が成功するとそのファイルディスクリプタを返す。
+      失敗すると -1 を返す。
 /-------------------------------------------------------------------*/
 int
 open_linda(char * hostname, int port){
@@ -168,16 +186,14 @@
     if (hostname[0]=='/') {
         /* Unix domain */
         if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == FAIL){
-            fprintf(stderr, "socket open error! errno :%d %s\n", errno,
-                    strerror(errno));
+	    perror("socket");
             return(-1);
         }
         serv_addr_un.sun_family = AF_UNIX;
         strcpy(serv_addr_un.sun_path, hostname);
         fprintf(stdout,"connecting ... %d\n", serv_addr.sin_port);
         if (connect(fd, (struct sockaddr *)&serv_addr_un,sizeof(serv_addr_un)) == FAIL){
-            fprintf(stderr,"connection error! errno :%d %s\n", errno,
-                    strerror(errno));
+	    perror("connect");
             close(fd);
             return(-1);
         }
@@ -185,8 +201,7 @@
     } else {
         /* INET domain */
         if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == FAIL){
-            fprintf(stderr, "socket open error! errno :%d %s\n", errno,
-                    strerror(errno));
+			perror("socket");
             return(-1);
         }
         if ((hoste = gethostbyname(SERVER_NAME)) == NULL){
@@ -228,16 +243,14 @@
     if (hostname[0]=='/') {
         /* Unix domain */
         if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == FAIL){
-            fprintf(stderr, "socket open error! errno :%d %s\n", errno,
-                    strerror(errno));
+			perror("socket");
             return(-1);
         }
         serv_addr_un.sun_family = AF_UNIX;
         strcpy(serv_addr_un.sun_path, hostname);
-        fprintf(stdout,"connecting ... %d\n", serv_addr.sin_port);
+        DEB(fprintf(stdout,"connecting ... %d\n", serv_addr.sin_port));
         if (connect(fd, (struct sockaddr *)&serv_addr_un,sizeof(serv_addr_un)) == FAIL){
-            fprintf(stderr,"connection error! errno :%d %s\n", errno,
-                    strerror(errno));
+			perror("connect");
             close(fd);
             return(-1);
         }
@@ -245,8 +258,7 @@
     } else {
         /* INET domain */
         if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == FAIL){
-            fprintf(stdout, "socket open error! errno :%d %s\n", errno,
-                    strerror(errno));
+			perror("socket");
             return(-2);
         }
 	serv_addr.sin_family = AF_INET;
@@ -267,12 +279,11 @@
             setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
                         (char *) &tmp, sizeof (int));
         }
-        fprintf(stdout,"connecting ... %d \n", ntohs(serv_addr.sin_port));
-        fprintf(stdout," serv_addr.sin_port ... %d \n", ntohs(serv_addr.sin_port));
+        DEB(fprintf(stdout,"connecting ... %d \n", ntohs(serv_addr.sin_port)));
+        DEB(fprintf(stdout," serv_addr.sin_port ... %d \n", ntohs(serv_addr.sin_port)));
 	//fprintf(stdout," serv_addr.sin_addr.s_addr... %s\n", serv_addr.sin_addr.s_addr);
         if (connect(fd, (struct sockaddr *)&serv_addr,sizeof(serv_addr)) == FAIL){
-            fprintf(stdout,"connection error! errno :%d %s\n", errno,
-                    strerror(errno));
+			perror("connect");
             close(fd);
             return(-4);
         }
@@ -281,7 +292,7 @@
     FD_SET(fd, &g_fds);
     if (g_max_fds < fd) g_max_fds = fd;
     
-    fprintf(stdout," connect middle server %d\n", fd);
+    DEB(fprintf(stdout," connect middle server %d\n", fd));
     return fd;
 }
 
@@ -289,12 +300,12 @@
 /*-------------------------------------------------------------------/
   int
   close_linda(int tspace_id):
-      ³Ƥ륿ץ륹ڡؤ³ڤ롣
-      åȤĤg_fds 鳰
-  :
-      tspace_id - Ĥ륿ץ륹ڡID
-  ֤:
-      close 
+      接続しているタプルスペースへの接続を切る。
+      ソケットを閉じ、g_fds から外す。
+  引数:
+      tspace_id - 閉じるタプルスペースのID
+  返り値:
+      close の値
 /-------------------------------------------------------------------*/
 int
 close_linda(int tspace_id){
@@ -314,15 +325,15 @@
   int
   psx_out (unsigned int tspace_id, unsigned int id,
            unsigned char *data, unsigned int size):
-      outޥɤCOMMAND塼ί롣
+      outコマンドをCOMMANDキューへ溜める。
 
-  :
-      tspace_id - ץ륹ڡID
-      id        - ץID
-      data      - ǡ
-      size      - dataΥ
-  ֤:
-      ֹ
+  引き数:
+      tspace_id - タプルスペースのID
+      id        - タプルのID
+      data      - 送信するデータ
+      size      - dataのサイズ
+  返り値:
+      シーケンス番号
 /-------------------------------------------------------------------*/
 int
 psx_out(unsigned int tspace_id, unsigned int id,
@@ -340,18 +351,18 @@
   int
   psx_ld (unsigned tspace_id, unsigned int id,
           char mode, void(*callback)(char*,void*), void * obj):
-      in,read,waitʤɤμޥɤCOMMAND塼ί롣
-      psx_in,psx_rd,psx_wait_rdʤɤ֤Ƥ롣
+      in,read,waitなどの受信コマンドをCOMMANDキューへ溜める。
+      psx_in,psx_rd,psx_wait_rdなどに置き換えられている。
       
-  :
-      tspace_id- ץ륹ڡID
-      id       - ץID
-      mode     - i,r,w ʸꡢơin,read,waitɽƤ롣
-      callback - ХåѤδؿؤΥݥ󥿡
-                 ѤʤNULL򤤤롣
-      obj      - ХåѤؿΰ
-  ֤:
-      psx_queuemalloc줿REPLY¤ΤؤΥݥ
+  引き数:
+      tspace_id- タプルスペースのID
+      id       - タプルのID
+      mode     - i,r,w の文字を取り、各々in,read,waitを表している。
+      callback - コールバックを使用する場合の関数へのポインタ。
+                 使用しない場合はNULLをいれる。
+      obj      - コールバックで用いる関数の引き数。
+  返り値:
+      psx_queue内でmallocされたREPLY構造体へのポインタ
 /-------------------------------------------------------------------*/
 int
 psx_ld(unsigned int tspace_id, unsigned int id,
@@ -366,13 +377,13 @@
 /*-------------------------------------------------------------------/
   unsigned char *
   psx_reply (int seq):
-      Ф褿ǡ֤
+      サーバから答えが来たデータを返す。
 
-  :
-      seq - psx_ld()֤͡
-  ֤:
-      seqбǡ֤ǡޤƤʤ
-      NULL֤
+  引き数:
+      seq - psx_ld()が返した値。
+  返り値:
+      seqに対応したデータを返す。データをまだ受信していない場合は
+      NULLを返す。
 /-------------------------------------------------------------------*/
 unsigned char *
 psx_reply(int seq){
@@ -420,8 +431,8 @@
 /*-------------------------------------------------------------------/
   void
   psx_sync_n ():
-      Фȥǡ򤹤롣COMMAND塼ίޤäǡ
-      Ф褿ǡбREPLYؤ롣
+      サーバとデータの送受信をする。COMMANDキューに溜まったデータを
+      送信し、サーバから送られて来たデータを対応するREPLYへいれる。
 /-------------------------------------------------------------------*/
 #define TIMEDELTA       10
 void
@@ -461,23 +472,23 @@
   psx_queue (unsigned int tspace_id, unsigned int id,
              unsigned int size, unsigned char *data, char mode,
              void(*callback)(char*,void*), void * obj):
-      out,in,read,waitʤɤΥޥɤCOMMAND塼ί롣ǡ
-      륳ޥ(in,read,wait)ΤȤϼäȤ˥ǡ
-      ǼREPLY¤Τ롣
+      out,in,read,waitなどのコマンドをCOMMANDキューに溜める。データを
+      受信するコマンド(in,read,wait)のときは受け取ったときにデータを
+      格納するREPLY構造体を作る。
 
-  :
-      tspace_id- 西ץ륹ڡID
-      id       - TUPLE SpaceID
-      size     - dataΥ
-      data     - ǡNULL
-      mode     - ޥɤΥ⡼(out,in,read,wait ϳơchar: o,i,r,w)
-      callback - ХåѤδؿؤΥݥ󥿡
-                 ѤʤNULL
-      obj      - ХåѤؿ˰Ϥǡ
-  ֤:
-       - mallocREPLY¤ΤؤΥݥ󥿡outξ
-                     0֤롣
-      Ԥ - FAIL(-1)֤롣
+  引き数:
+      tspace_id- 送信先タプルスペースのID
+      id       - アクセスするTUPLE SpaceのID
+      size     - dataのサイズ
+      data     - 送信するデータ。受信時はNULL。
+      mode     - コマンドのモード(out,in,read,wait は各々char型: o,i,r,w)
+      callback - コールバックを使用する場合の関数へのポインタ。
+                 使用しない場合はNULL。
+      obj      - コールバックで用いる関数に引き渡すデータ。
+  返り値:
+      成功した場合 - mallocしたREPLY構造体へのポインタ。outの場合は
+                     0が返る。
+      失敗した場合 - FAIL(-1)が返る。
 /-------------------------------------------------------------------*/
 static int
 psx_queue(unsigned int tspace_id, unsigned int id,
@@ -504,14 +515,14 @@
         q_end = q_end->next;
     }
     
-    /* size  DATASIZE */
+    /* size は DATASIZE */
     if ((q_end->command = (unsigned char *) malloc(size+LINDA_HEADER_SIZE)) == NULL) {
         psx_free(q_end);
         c->next = NULL;
         return(FAIL);
     }
 
-    /* ǡ׵(in,rd,wait)ʤѤȢѰ */
+    /* データ受け取り要求(in,rd,wait)なら受け取り用の箱を用意 */
     if (mode != 'o') {  
         if (reply == NULL){
             if ((reply = (REPLY *) malloc (sizeof(REPLY))) == NULL){
@@ -525,7 +536,7 @@
             p = r_end->next; r_end = p; p->next = NULL;
         }
         p->mode = '?';
-        p->seq = (int)p;  // ¤ΤΥɥ쥹Ǽ
+        p->seq = (int)p;  // 構造体のアドレスで識別
         p->callback = callback;
         p->obj = obj;
         PSX_Debug(("psx_queue: seq %d reply %x p %x r_end %x",seq,reply,p,r_end));
@@ -559,12 +570,12 @@
 /*-------------------------------------------------------------------/
   static void
   unix_chkserv (int ps):
-      Фǡ(TUPLE)롣REPLY¤Τ˥Хåؿ
-      ꤵƤФδؿ¹ԤREPLY¤Τ򥭥塼
-      ХåؿꤵƤʤREPLY¤Τ˥ǡ
-      Ϥ
-  :
-      ps - ³Ƥ륿ץ륹ڡΥå
+      サーバからデータ(TUPLE)を受け取る。REPLY構造体にコールバック関数
+      が指定されていればその関数を実行し、REPLY構造体をキューから取り
+      除く。コールバック関数が指定されていなければREPLY構造体にデータ
+      を引き渡す。
+  引数:
+      ps - 接続しているタプルスペースのソケット
 /-------------------------------------------------------------------*/
 static void
 unix_chkserv(int ps){
@@ -574,15 +585,14 @@
     unsigned char * tuple = 0;
 
     if((i=read(ps,&npkt,INT_SIZE))<0) {
-        fprintf(stderr, "size read error! on fd:%d %s\n", ps,
-                strerror(errno));
+		perror("read");
         exit(1);
     }
     pkt = ntohl(npkt);
     DEB(printf("pkt: %d\n",pkt));
     DEB(fprintf(stdout, "psx_chkserv: queue number: %d , size = %d\n", i, pkt));
     if((tuple = (unsigned char *)malloc(pkt))==NULL){
-        fprintf(stderr,"allocate error! errno :%d %s",errno,strerror(errno));
+		perror("malloc");
         exit(1);
     }
     for(a=0;a<pkt;a+=i) {
@@ -649,16 +659,16 @@
 /*-------------------------------------------------------------------/
   static unsigned int
   get_int(unsigned char * tuple, int offset):
-      TUPLEΥإå˳Ǽ줿 int Υǡ뤿δؿ
-      psx_get_datalength()  psx_get_seq() ƤФ롣
+      TUPLEのヘッダに格納された int型 のデータを得るための関数
+      psx_get_datalength() と psx_get_seq() から呼ばれる。
 
-  :
-      tuple  - إåޤTUPLEpsx_reply()ΤǤ⤤
-      offset - ǡΥեåȡLINDA_DATA_LENGTH_OFFSET
-                LINDA_SEQ_OFFSET
+  引き数:
+      tuple  - ヘッダ情報も含んだTUPLE。psx_reply()で得たものでもいい。
+      offset - 取りだすデータのオフセット。LINDA_DATA_LENGTH_OFFSET
+               か LINDA_SEQ_OFFSET。
 
-  ֤:
-      ꤷեåȤ˳ǼƤ(int)
+  返り値:
+      指定したオフセットに格納されていた数値(int型)
 /-------------------------------------------------------------------*/
 static unsigned int
 get_int(unsigned char * tuple, int offset){
--- a/tools/Linda_library/lindaapi.h	Sat Jun 06 14:33:59 2009 +0900
+++ b/tools/Linda_library/lindaapi.h	Wed Oct 21 21:11:43 2009 +0900
@@ -1,7 +1,7 @@
 /*  $Id$ */
 
 /*----------------------------------------------------------------------
-  ޥ
+  マクロ定義
 ----------------------------------------------------------------------*/
 
 #define FAIL            (-1)
@@ -15,7 +15,7 @@
 #define LDSERV_PORT     11511
 
 /*----------------------------------------------------------------------
- ѥåȥեޥå
+ パケットフォーマット
  char     short  int    int
  Mode +   ID   + Seq  + Data_len + Padding + Data
  0        1      3      7          11        12
@@ -28,7 +28,7 @@
 #define LINDA_HEADER_SIZE          12
 
 /*----------------------------------------------------------------------
-  ¤
+  構造体定義
 ----------------------------------------------------------------------*/
 typedef struct psx_reply{
     unsigned char *answer;