annotate Renderer/Engine/lindaapi.cc @ 572:096a900bd9d3 draft

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 23 Oct 2009 00:40:24 +0900
parents 3bc98f6d31ff
children 341f1f881a9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
1 // $Id$
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 /*----------------------------------------------------------------------
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
5 インクルードファイル読み込み
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 ----------------------------------------------------------------------*/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include <stdio.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include <string.h>
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
9 #include <stdlib.h>
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
10 #include <sys/time.h>
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include <unistd.h>
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
12 #include <netinet/in.h>
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include <sys/select.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include <sys/types.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #include <sys/socket.h>
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
16 #include <netdb.h>
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include <netinet/tcp.h>
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
18 #include <sys/un.h>
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #include <errno.h>
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
20 #include <arpa/inet.h>
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "lindaapi.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
24
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #if 0
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #define PSX_Debug(deb) (putchar(PS_DEB)),\
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 (printf deb ),\
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 (putchar(PS_DEB))
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
29 #define DEB(a)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #else
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
31 #define PSX_Debug(deb)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #define DEB(a) /* a */
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #endif
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
35 /* Global Variables */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
36 static COMMAND *q_top, *q_end; /* コマンドキュー */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
37 static REPLY *reply, *r_end; /* 受け取り用キュー */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
38 static int qsize; /* コマンドキューのサイズ */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
39 static fd_set g_fds; /* 接続しているタプルスペース群のFD(FileDiscripter)を保持 */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
40 static int g_max_fds; /* 監視するFDの最大値 */
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
42 /* Static Functions */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
43 static void unix_chkserv(int ps);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
44 void psx_free(void *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
45 static int psx_queue(unsigned int tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
46 unsigned int size, unsigned char *data, char mode,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
47 void(*callback)(unsigned char *,void *),void * obj);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 #ifdef COUNT_PACKET
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 // print packet count message per PRINT_INTERVAL sec
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 #define PRINT_INTERVAL 4
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
52 static void count_packet(char type);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 /*-------------------------------------------------------------------/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
55 static void
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 count_packet (char type):
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
57 パケットの送受信カウントする
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
59 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
60 type - 送信、受信 (char型: s,r)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 /-------------------------------------------------------------------*/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
62 static void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
63 count_packet(char type)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 static int send_packet=-1,receive_packet=0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 static struct timeval start,now,previous;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
67
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 if (out_packet == -1) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 gettimeofday(&start,NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 gettimeofday(&previous,NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 send_packet = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 printf("packet\tout\tread\t\ttime\n");
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
74
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 if (type == 's') {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 send_packet++;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 } else if (type == 'r') {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 receive_packet++;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 fprintf(stderr,"No type in count_packet function\n");
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 return;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
83
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 gettimeofday(&now,NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 if ((now.tv_sec-previous.tv_sec) > PRINT_INTERVAL) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 printf("log\t%d\t%d\t%ld\n",
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 send_packet,receive_packet,now.tv_sec-start.tv_sec);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 fflush(stdout);
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
89
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 previous.tv_sec = now.tv_sec;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 send_packet = receive_packet = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 #endif
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 #define unix_read_w read
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
98
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
99
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
100 static int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
101 unix_write(int fd,unsigned char *buf,unsigned int size) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
102 unsigned int count=0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
103 uint32_t nsize;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
105 /* これから送信するデータのサイズをまず送信 */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
106 nsize = htonl(size);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
107 write(fd, &nsize, INT_SIZE);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
108
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
109 /* 目的のデータを送信 */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
110 while (count < size) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
111 count += write(fd, buf+count, size-count);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 #ifdef COUNT_PACKET
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 count_packet('s');
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 #endif
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
116 return count+INT_SIZE;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 #define unix_write_w unix_write
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 #define SERV_NAME unix_port
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 #define PROTO_NAME "tcp"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 #define SERVER_NAME hostname
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 #define MAX_REQ 16
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
126
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
127
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
128 /*-------------------------------------------------------------------/
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
129 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
130 init_linda():
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
131 大域変数の初期化等を行なう
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
132 /-------------------------------------------------------------------*/
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
133 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
134 init_linda() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
135 FD_ZERO(&g_fds);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
136 /* 大域変数はゼロクリアされる
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
137 g_max_fds = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
138 q_end = q_top = NULL;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
139 r_end = reply = NULL;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
140 qsize = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
141 */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
142 }
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 /*-------------------------------------------------------------------/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 int
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
147 open_linda (char * hostname, int port):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
148 Lindaサーバとのコネクションを確立し、タプルスペースのIDを返す。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
149 現在はファイルディスクリプタを返している。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
151 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
152 hostname - サーバのホスト名
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
153 port - サーバのポート番号
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
154 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
155 コネクション確立が成功するとそのファイルディスクリプタを返す。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
156 失敗すると -1 を返す。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 /-------------------------------------------------------------------*/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 int
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
159 open_linda(char * hostname, int port){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
160 int fd;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
161 struct hostent *hoste;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
162 struct sockaddr_in serv_addr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
163 struct sockaddr_un serv_addr_un;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
164
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 if (hostname[0]=='/') {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 /* Unix domain */
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == FAIL){
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
168 perror("socket");
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 return(-1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 serv_addr_un.sun_family = AF_UNIX;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 strcpy(serv_addr_un.sun_path, hostname);
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
173 fprintf(stdout,"connecting ... %d\n", serv_addr.sin_port);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 if (connect(fd, (struct sockaddr *)&serv_addr_un,sizeof(serv_addr_un)) == FAIL){
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
175 perror("connect");
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 close(fd);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 return(-1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
179
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 /* INET domain */
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == FAIL){
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
183 perror("socket");
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 return(-1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
186 if ((hoste = gethostbyname(SERVER_NAME)) == NULL){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 fprintf(stderr,"hostname error\n");
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 close(fd);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 return(-1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 serv_addr.sin_family = AF_INET;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
192 serv_addr.sin_port = port;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 serv_addr.sin_addr.s_addr = ((struct in_addr *)(hoste->h_addr))->s_addr;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 if (serv_addr.sin_family == AF_INET) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 int tmp = 1;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 (char *) &tmp, sizeof (int));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
199 fprintf(stdout,"connecting ... %d\n", serv_addr.sin_port);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 if (connect(fd, (struct sockaddr *)&serv_addr,sizeof(serv_addr)) == FAIL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 fprintf(stderr,"connection error! errno :%d %s\n", errno,
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 strerror(errno));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 close(fd);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 return(-1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
208 FD_SET(fd, &g_fds);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
209 if (g_max_fds < fd) g_max_fds = fd;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
210
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 fprintf(stdout," connect middle server %d\n", fd);
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
212 return fd;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
213 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
214
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
215 int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
216 open_linda_java(char * hostname, int port){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
217 int fd;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
218 struct hostent *hoste;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
219 struct sockaddr_in serv_addr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
220 struct sockaddr_un serv_addr_un;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
221
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
222 if (hostname[0]=='/') {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
223 /* Unix domain */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
224 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == FAIL){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
225 perror("socket");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
226 return(-1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
227 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
228 serv_addr_un.sun_family = AF_UNIX;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
229 strcpy(serv_addr_un.sun_path, hostname);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
230 DEB(fprintf(stdout,"connecting ... %d\n", serv_addr.sin_port));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
231 if (connect(fd, (struct sockaddr *)&serv_addr_un,sizeof(serv_addr_un)) == FAIL){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
232 perror("connect");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
233 close(fd);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
234 return(-1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
235 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
236
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
237 } else {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
238 /* INET domain */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
239 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == FAIL){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
240 perror("socket");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
241 return(-2);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
242 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
243 serv_addr.sin_family = AF_INET;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
244 serv_addr.sin_port = htons(port);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
245
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
246 serv_addr.sin_addr.s_addr = inet_addr(hostname);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
247 if (serv_addr.sin_addr.s_addr == 0xffffffff) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
248 if ((hoste = gethostbyname(hostname)) == NULL){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
249 fprintf(stdout, "hostname error\n");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
250 close(fd);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
251 return(-1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
252 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
253 serv_addr.sin_addr.s_addr = *(unsigned int *)hoste->h_addr_list[0];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
254 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
255
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
256 if (serv_addr.sin_family == AF_INET) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
257 int tmp = 1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
258 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
259 (char *) &tmp, sizeof (int));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
260 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
261 DEB(fprintf(stdout,"connecting ... %d \n", ntohs(serv_addr.sin_port)));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
262 DEB(fprintf(stdout," serv_addr.sin_port ... %d \n", ntohs(serv_addr.sin_port)));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
263 //fprintf(stdout," serv_addr.sin_addr.s_addr... %s\n", serv_addr.sin_addr.s_addr);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
264 if (connect(fd, (struct sockaddr *)&serv_addr,sizeof(serv_addr)) == FAIL){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
265 perror("connect");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
266 close(fd);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
267 return(-4);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
268 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
269 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
270
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
271 FD_SET(fd, &g_fds);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
272 if (g_max_fds < fd) g_max_fds = fd;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
273
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
274 DEB(fprintf(stdout," connect middle server %d\n", fd));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
275 return fd;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
276 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
277
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
278
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
279 /*-------------------------------------------------------------------/
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
280 int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
281 close_linda(int tspace_id):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
282 接続しているタプルスペースへの接続を切る。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
283 ソケットを閉じ、g_fds から外す。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
284 引数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
285 tspace_id - 閉じるタプルスペースのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
286 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
287 close の値
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
288 /-------------------------------------------------------------------*/
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
289 int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
290 close_linda(int tspace_id){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
291 int retval;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
292 int i;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
293 if ((retval = close(tspace_id)) == 0) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
294 FD_CLR(tspace_id, &g_fds);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
295 if (g_max_fds == tspace_id) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
296 for (i = g_max_fds-1; FD_ISSET(i, &g_fds) && i; i--);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
297 g_max_fds = i;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
298 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
299 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
300 return retval;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 /*-------------------------------------------------------------------/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 int
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
305 psx_out (unsigned int tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
306 unsigned char *data, unsigned int size):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
307 outコマンドをCOMMANDキューへ溜める。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
309 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
310 tspace_id - タプルスペースのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
311 id - タプルのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
312 data - 送信するデータ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
313 size - dataのサイズ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
314 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
315 シーケンス番号
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 /-------------------------------------------------------------------*/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 int
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
318 psx_out(unsigned int tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
319 unsigned char *data, unsigned int size){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
320 int r;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
321 if ((r = psx_queue(tspace_id, id, size, data, 'o', NULL, NULL)) == FAIL) {
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 DEB( fprintf(stdout, "psx_out: size = %d, command = %s\n",
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 q_end->size, q_end->command+LINDA_HEADER_SIZE));
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
326 return(r);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 /*-------------------------------------------------------------------/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 int
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
331 psx_ld (unsigned tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
332 char mode, void(*callback)(char*,void*), void * obj):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
333 in,read,waitなどの受信コマンドをCOMMANDキューへ溜める。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
334 psx_in,psx_rd,psx_wait_rdなどに置き換えられている。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
335
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
336 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
337 tspace_id- タプルスペースのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
338 id - タプルのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
339 mode - i,r,w の文字を取り、各々in,read,waitを表している。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
340 callback - コールバックを使用する場合の関数へのポインタ。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
341 使用しない場合はNULLをいれる。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
342 obj - コールバックで用いる関数の引き数。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
343 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
344 psx_queue内でmallocされたREPLY構造体へのポインタ
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 /-------------------------------------------------------------------*/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 int
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
347 psx_ld(unsigned int tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
348 char mode, void(*callback)(unsigned char *,void *), void * obj){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 int r;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
350 if ((r = psx_queue(tspace_id, id, 0, NULL, mode, callback, obj)) == FAIL) {
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 return(r);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 /*-------------------------------------------------------------------/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 unsigned char *
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 psx_reply (int seq):
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
359 サーバから答えが来たデータを返す。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
361 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
362 seq - psx_ld()が返した値。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
363 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
364 seqに対応したデータを返す。データをまだ受信していない場合は
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
365 NULLを返す。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 /-------------------------------------------------------------------*/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 unsigned char *
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
368 psx_reply(unsigned int seq){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 REPLY *p, *q;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
370 unsigned char *ans;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
371
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 DEB(fprintf(stdout, "psx_reply: search of seq = %d\n", seq));
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
373 PSX_Debug(("psx_reply: seq %d", seq));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
374 for(q = NULL,p = reply; p; q = p,p = p->next){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
375 if (p->seq == seq){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 DEB(fprintf(stdout, "psx_reply: match of seq = %d\n", seq));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 if (p->mode == '!'){
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
378 ans = p->answer;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 if (q == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 reply = p->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 if(p==r_end) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 r_end = p->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 q->next = p->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 if(p==r_end) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 r_end = q;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
390 PSX_Debug(("psx_reply: reply %x r_end %x p %x q %x",reply,r_end,p,q));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
391 psx_free(p);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 DEB( for(p=reply;p;p=p->next) { PSX_Debug(("psx_queue dump: seq %d mode %c %x %x",p->seq,p->mode,p,p->next))});
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 DEB( fprintf(stdout, "psx_reply: returned answer = %s\n", ans));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 PSX_Debug(("psx_reply: answer %s",ans));
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
395 return(ans);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 if (p->mode == '?'){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 DEB(fprintf(stdout, "psx_reply: don't accept anser\n"));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 return(NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 PSX_Debug(("psx_reply: no match seq %d",seq));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 DEB(fprintf(stdout, "psx_reply: no match of seq\n"));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 return(NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 /*-------------------------------------------------------------------/
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 psx_sync_n ():
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
413 サーバとデータの送受信をする。COMMANDキューに溜まったデータを
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
414 送信し、サーバから送られて来たデータを対応するREPLYへいれる。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 /-------------------------------------------------------------------*/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
416 #define TIMEDELTA 10
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 psx_sync_n(){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 int acount;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
420 int i;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 COMMAND *c, *t;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
423 fd_set tmp;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 struct timeval timeout;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 timeout.tv_sec=0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 timeout.tv_usec=TIMEDELTA * 1000;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 acount = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 while (q_top != NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 c = q_top;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
431 unix_write_w(c->tspace_id, c->command, c->size);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
432 psx_free(c->command);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 t = c->next;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
434 psx_free(c);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
435 q_top = c = t;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
436 qsize--;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
438
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
439 tmp = g_fds;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
440 while(select(g_max_fds+1, &tmp, NULL, NULL, &timeout) > 0) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
441 for (i = 0; i < g_max_fds+1; i++) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
442 if (FD_ISSET(i, &tmp)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
443 unix_chkserv(i);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
444 }
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
446 }
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 /*-------------------------------------------------------------------/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
450 static int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
451 psx_queue (unsigned int tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
452 unsigned int size, unsigned char *data, char mode,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
453 void(*callback)(char*,void*), void * obj):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
454 out,in,read,waitなどのコマンドをCOMMANDキューに溜める。データを
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
455 受信するコマンド(in,read,wait)のときは受け取ったときにデータを
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
456 格納するREPLY構造体を作る。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
458 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
459 tspace_id- 送信先タプルスペースのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
460 id - アクセスするTUPLE SpaceのID
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
461 size - dataのサイズ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
462 data - 送信するデータ。受信時はNULL。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
463 mode - コマンドのモード(out,in,read,wait は各々char型: o,i,r,w)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
464 callback - コールバックを使用する場合の関数へのポインタ。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
465 使用しない場合はNULL。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
466 obj - コールバックで用いる関数に引き渡すデータ。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
467 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
468 成功した場合 - mallocしたREPLY構造体へのポインタ。outの場合は
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
469 0が返る。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
470 失敗した場合 - FAIL(-1)が返る。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 /-------------------------------------------------------------------*/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
472 static int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
473 psx_queue(unsigned int tspace_id, unsigned int id,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
474 unsigned int size, unsigned char *data, char mode,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
475 void(*callback)(unsigned char *,void *), void * obj){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 REPLY *p;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 COMMAND *c;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
478
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
479 if (qsize >= MAX_QUEUE) {
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 // PSX_Debug(("max queue: qsize=%d",qsize));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 psx_sync_n();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
483
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
484 if (q_top == NULL) {
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 if ((q_top = (COMMAND *) malloc (sizeof(COMMAND))) == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 c = q_end = q_top;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 if ((q_end->next = (COMMAND *) malloc (sizeof(COMMAND))) == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 c = q_end;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 q_end = q_end->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
496
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
497 /* size は DATASIZE */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
498 if ((q_end->command = (unsigned char *) malloc(size+LINDA_HEADER_SIZE)) == NULL) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
499 psx_free(q_end);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 c->next = NULL;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
504 /* データ受け取り要求(in,rd,wait)なら受け取り用の箱を用意 */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
505 if (mode != 'o') {
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 if (reply == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 if ((reply = (REPLY *) malloc (sizeof(REPLY))) == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 p = r_end = reply; p->next = NULL;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 if ((r_end->next = (REPLY *) malloc (sizeof(REPLY))) == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 return(FAIL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 p = r_end->next; r_end = p; p->next = NULL;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 p->mode = '?';
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
518 p->seq = (int)p; // 構造体のアドレスで識別
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 p->callback = callback;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 p->obj = obj;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 PSX_Debug(("psx_queue: seq %d reply %x p %x r_end %x",seq,reply,p,r_end));
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
522 } else {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
523 p = 0;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 q_end->command[LINDA_MODE_OFFSET] = mode;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 q_end->command[LINDA_ID_OFFSET] = id >> 8;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 q_end->command[LINDA_ID_OFFSET+1] = id & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 q_end->command[LINDA_SEQ_OFFSET] = ((int)p>>24) & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 q_end->command[LINDA_SEQ_OFFSET+1] = ((int)p>>16) & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 q_end->command[LINDA_SEQ_OFFSET+2] = ((int)p>>8) & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 q_end->command[LINDA_SEQ_OFFSET+3] = ((int)p) & 0xff;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
534
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 q_end->command[LINDA_DATA_LENGTH_OFFSET] = (size>>24) & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 q_end->command[LINDA_DATA_LENGTH_OFFSET+1] = (size>>16) & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 q_end->command[LINDA_DATA_LENGTH_OFFSET+2] = (size>>8) & 0xff;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 q_end->command[LINDA_DATA_LENGTH_OFFSET+3] = (size) & 0xff;
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
539
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 q_end->size = size+LINDA_HEADER_SIZE; /* command size */
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
541 q_end->tspace_id = tspace_id; /* destination id */
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
542 q_end->next = NULL;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
543 qsize++;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
544 if (data && size>0)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
545 memcpy(q_end->command+LINDA_HEADER_SIZE, data, size);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 return((int)p);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 /*-------------------------------------------------------------------/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
550 static void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
551 unix_chkserv (int ps):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
552 サーバからデータ(TUPLE)を受け取る。REPLY構造体にコールバック関数
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
553 が指定されていればその関数を実行し、REPLY構造体をキューから取り
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
554 除く。コールバック関数が指定されていなければREPLY構造体にデータ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
555 を引き渡す。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
556 引数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
557 ps - 接続しているタプルスペースのソケット
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 /-------------------------------------------------------------------*/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
559 static void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
560 unix_chkserv(int ps){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
561 int i,pkt,npkt,mode;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
562 unsigned int k;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 REPLY *r,*prev;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 int a;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 unsigned char * tuple = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
566
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 if((i=read(ps,&npkt,INT_SIZE))<0) {
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
568 perror("read");
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 exit(1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 pkt = ntohl(npkt);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 DEB(printf("pkt: %d\n",pkt));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 DEB(fprintf(stdout, "psx_chkserv: queue number: %d , size = %d\n", i, pkt));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 if((tuple = (unsigned char *)malloc(pkt))==NULL){
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
575 perror("malloc");
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 exit(1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 for(a=0;a<pkt;a+=i) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 if((i=unix_read_w(ps,tuple+a,pkt-a))<0) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 fprintf(stderr, "psx_chkserv: read error! on i=%d pkt=%d %s\n",
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 i, pkt, strerror(errno));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 exit(1);//close(ps);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
585
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 #ifdef COUNT_PACKET
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 count_packet('r');
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 #endif
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
589 mode = psx_get_mode(tuple);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
590 i = psx_get_id(tuple);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
591 k = psx_get_seq(tuple);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
592 PSX_Debug(("psx_chkserv: anser packet size = %d id %d seq %d", pkt,i,k));
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 DEB(fprintf(stdout, "psx_chkserv: data from server: %s id=%d seq = %d\n", tuple, i, k));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 DEB (
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 for(p=reply;p;p=p->next) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 PSX_Debug(printf("psx_queue dump: seq %d mode %c %x %x",p->seq,p->mode,p,p->next));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 })
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
598
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 for(prev = NULL,r = reply; r; prev = r,r = r->next){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 DEB(fprintf(stdout,"seq: %d\n",r->seq);)
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
601 if (r->seq == k){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 if(r->callback){ // call callback function
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
603 (*r->callback)(tuple,r->obj);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 if (prev == NULL){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 reply = r->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 if(r == r_end) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 r_end = r->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 } else {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 prev->next = r->next;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 if(r == r_end) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 r_end = prev;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 }
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
615 psx_free(r);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 }else{ // normal reply
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 PSX_Debug(("psx_chkserv: copy answer r %x seq %d",r,k));
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
618 if(mode == 'a'){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
619 r->answer = tuple;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
620 }else{
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
621 r->answer = NULL;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
622 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
623 r->mode = '!';
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 break;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 tuple = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 if (!r){
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 DEB(fprintf(stdout, "unix_chkserv: accepted seq %d does not match. \n",k));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
633
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
634 void psx_free(void *tuple)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 free(tuple);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
638
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 /*-------------------------------------------------------------------/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
640 static unsigned int
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 get_int(unsigned char * tuple, int offset):
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
642 TUPLEのヘッダに格納された int型 のデータを得るための関数
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
643 psx_get_datalength() と psx_get_seq() から呼ばれる。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
645 引き数:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
646 tuple - ヘッダ情報も含んだTUPLE。psx_reply()で得たものでもいい。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
647 offset - 取りだすデータのオフセット。LINDA_DATA_LENGTH_OFFSET
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
648 か LINDA_SEQ_OFFSET。
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
649
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
650 返り値:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
651 指定したオフセットに格納されていた数値(int型)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 /-------------------------------------------------------------------*/
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
653 static unsigned int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
654 get_int(unsigned char * tuple, int offset){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
655 unsigned int i;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 i = (tuple[offset] <<24) +
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 (tuple[offset+1]<<16) +
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 (tuple[offset+2]<<8) +
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 (tuple[offset+3]);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 return i;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
662
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
663 unsigned int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
664 psx_get_datalength(unsigned char * tuple){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 return get_int(tuple,LINDA_DATA_LENGTH_OFFSET);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
668 unsigned char *
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
669 psx_get_data(unsigned char * tuple) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
670 return tuple + LINDA_HEADER_SIZE;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
672
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
673 unsigned int
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
674 psx_get_seq(unsigned char * tuple){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 return get_int(tuple,LINDA_SEQ_OFFSET);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
677
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
678 unsigned short
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
679 psx_get_id(unsigned char * tuple){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
680 return (tuple[LINDA_ID_OFFSET] * 256 + tuple[LINDA_ID_OFFSET+1]);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
682
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
683 unsigned char
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
684 psx_get_mode(unsigned char * tuple){
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 return tuple[LINDA_MODE_OFFSET];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
687
572
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
688 static
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
689 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
690 set_int_to_char(unsigned char * tuple, int i, int offset){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
691 tuple[offset] = (i>>24) & 0xff;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
692 tuple[offset+1] = (i>>16) & 0xff;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
693 tuple[offset+2] = (i>>8) & 0xff;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
694 tuple[offset+3] = (i) & 0xff;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
695 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
696
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
697 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
698 psx_set_datalength(unsigned char * tuple, int length){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
699 set_int_to_char(tuple,length,LINDA_DATA_LENGTH_OFFSET);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
700 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
701
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
702
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
703 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
704 psx_set_seq(unsigned char * tuple, int seq){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
705 set_int_to_char(tuple,seq,LINDA_SEQ_OFFSET);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
706 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
707
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
708 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
709 psx_set_id(unsigned char * tuple, short id){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
710 tuple[LINDA_ID_OFFSET] = id >> 8;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
711 tuple[LINDA_ID_OFFSET+1] = id & 0xff;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
712 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
713
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
714 void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
715 psx_set_mode(unsigned char * tuple, char mode){
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
716 tuple[LINDA_MODE_OFFSET] = mode;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
717 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
718
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
719
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
720
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 /* end */