Annotation of libaitrpc/example/tcliext.c, revision 1.1.2.2
1.1.2.1 misho 1: #include <stdio.h>
2: #include <sys/time.h>
3: #include <pthread.h>
4: #include <aitrpc.h>
5: #include "rc.h"
6:
7:
8: int main(int argc, char **argv)
9: {
10: rpc_cli_t *cli = NULL, *cli2 = NULL;
11: int c, i, ret;
12: ait_val_t tval, *v = NULL;
13: array_t *valz, *arr;
14: char *mem;
15: struct timeval after, before;
16:
17: // printf("MM model=%d\n", elwix_mm_inuse());
18: // getchar();
19: //
20: cli = rpc_cli_openClientExt(2, 1024 * 10, 2);
21: if (!cli) {
22: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
23: return 1;
24: }
25:
26: //#if 0
27: printf("\n\n1 pass>>> RPC ping\n\n");
28: for (i = 0; i < 1000; i++) {
29: gettimeofday(&before, NULL);
30: if ((ret = rpc_cli_ping(cli)) == -1) {
31: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
32: rpc_cli_closeClient(&cli);
33: return 127;
34: }
35: gettimeofday(&after, NULL);
36: printf("RPC ping seq[0x%04x] #%d --- %f\n", ret, i,
37: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
38: }
39: //#endif
40: //#if 0
41: printf("\n\n2 pass>>> RPC ping without reply!!!\n\n");
42: for (i = 0; i < 10; i++) {
43: gettimeofday(&before, NULL);
44: if (rpc_cli_execCall(cli, RPC_NOREPLY, CALL_SRVPING, NULL, &arr)) {
45: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
46: rpc_cli_closeClient2(&cli);
47: return 127;
48: }
49: gettimeofday(&after, NULL);
50: rpc_cli_freeCall(&arr);
51: printf("RPC ping #%d --- %f\n", i, (after.tv_sec - before.tv_sec) +
52: (after.tv_usec - before.tv_usec) / 1.e6);
53: }
54: //#if 0
1.1.2.2 ! misho 55: sleep(1);
1.1.2.1 misho 56: printf("\n\n3 pass>>> RPC ping\n\n");
57: for (i = 0; i < 10000; i++) {
58: gettimeofday(&before, NULL);
59: if ((ret = rpc_cli_ping(cli)) == -1) {
60: printf("error %d:: errno=%d %s\n", i, rpc_GetErrno(), rpc_GetError());
61: rpc_cli_closeClient(&cli);
62: return 127;
63: }
64: gettimeofday(&after, NULL);
65: printf("RPC ping seq[0x%04x] #%d --- %f\n", ret, i,
66: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
67: }
68: //#endif
69: //#endif
70:
71: #if 0
72: valz = ait_allocVars(3);
73: v = array(valz, 0, ait_val_t*);
74: AIT_SET_I32(v, 12345678);
75: v = array(valz, 1, ait_val_t*);
76: AIT_SET_STR(v, "gniah_blah SHMINK!");
77: v = array(valz, 2, ait_val_t*);
78: AIT_NEW_BLOB(v, 512);
79: if (rpc_cli_sendBLOB(cli2, v, blob43, 0) == -1) {
80: printf("!!!!! blob error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
81: ait_freeVars(&valz);
82: rpc_cli_closeBLOBClient(&cli2);
83: rpc_cli_closeClient(&cli);
84: e_free(blob43);
85: return 2;
86: } else
87: printf("Get BLOB = %x\n", AIT_GET_BLOB(v));
88:
89: /* test case for unknown blob ...
90: AIT_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
91: printf("test not found blob=%d\n", rpc_cli_getBLOB(cli2, &tval, (void**) &mem));
92: if (mem)
93: e_free(mem);
94: */
95:
96: // for (i = 0; i < 1000000; i++)
97: if ((ret = rpc_cli_execCall(cli, RPC_REPLY, RC_BBB, valz, &arr)) < 0) {
98: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
99: ait_freeVars(&valz);
100: rpc_cli_closeBLOBClient(&cli2);
101: rpc_cli_closeClient(&cli);
102: e_free(blob43);
103: return 2;
104: } else {
105: printf("ret=%d\n", ret);
106: if (arr) {
107: v = array(arr, 0, ait_val_t*);
108: printf("ret_val0:: %p %s len=%d type=%d\n",
109: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
110: v = array(arr, 1, ait_val_t*);
111: printf("ret_val1:: %d len=%d type=%d\n",
112: AIT_GET_I8(v), AIT_LEN(v), AIT_TYPE(v));
113: v = array(arr, 2, ait_val_t*);
114: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
115: AIT_ISEMPTY(v), AIT_GET_STR(v), AIT_LEN(v), AIT_TYPE(v));
116: //#if 0
117: v = array(arr, 3, ait_val_t*);
118: printf("ret_val3:: %X %d\n", AIT_GET_BLOB(v), AIT_LEN(v));
119: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, v, (void**) &mem));
120: // printf("+++++++++ test found blob=%d\n", rpc_cli_recvBLOB(cli2, v, (void**) &mem));
121: if (mem) {
122: printf("+++++++ BLOB=%s", mem);
123: e_free(mem);
124: }
125: //#endif
126: rpc_cli_freeCall(&arr);
127: }
128: }
129: ait_freeVars(&valz);
130: e_free(blob43);
131:
132: if (rpc_cli_execCall(cli, RPC_REPLY, RC_aaa, NULL, &arr) < 0) {
133: printf("error:: \"aaa\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
134: return 3;
135: }
136: printf("return=%d aaa arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
137:
138: if (rpc_cli_execCall(cli, RPC_REPLY, RC_big, NULL, &arr) < 0) {
139: printf("error:: \"big\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
140: } else
141: printf("return=%d big arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
142: ait_freeVars(&arr);
143:
144:
145: valz = ait_allocVars(1);
146: v = array(valz, 0, ait_val_t*);
147: AIT_SET_DATA(v, "1234567890", 11);
148: array_Set(valz, 0, v);
149: if (rpc_cli_execCall(cli, RPC_NOREPLY, RC_xxx, valz, &arr) < 0) {
150: printf("0) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
151: ait_freeVars(&valz);
152: if (arr)
153: rpc_cli_freeCall(&arr);
154: rpc_cli_closeBLOBClient(&cli2);
155: rpc_cli_closeClient(&cli);
156: return 3;
157: }
158: printf("0) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
159: ait_freeVars(&valz);
160: if (arr) {
161: printf("...REPLY --- ");
162: v = array(arr, 0, ait_val_t*);
163: printf("ret_val0:: %p %s len=%d type=%d\n",
164: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
165: rpc_cli_freeCall(&arr);
166: }
167:
168: valz = ait_allocVars(1);
169: v = array(valz, 0, ait_val_t*);
170: AIT_SET_DATA(v, "0987654321", 11);
171: array_Set(valz, 0, v);
172: if (rpc_cli_execCall(cli, RPC_REPLY, RC_xxx, valz, &arr) < 0) {
173: printf("1) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
174: ait_freeVars(&valz);
175: if (arr)
176: rpc_cli_freeCall(&arr);
177: rpc_cli_closeBLOBClient(&cli2);
178: rpc_cli_closeClient(&cli);
179: return 3;
180: }
181: printf("1) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
182: ait_freeVars(&valz);
183: if (arr) {
184: printf("@REPLY --- ");
185: v = array(arr, 0, ait_val_t*);
186: printf("ret_val0:: %p %s len=%d type=%d\n",
187: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
188: rpc_cli_freeCall(&arr);
189: }
190:
191:
192: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCLIENTS, NULL, &arr) < 0) {
193: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
194: rpc_cli_closeBLOBClient(&cli2);
195: rpc_cli_closeClient(&cli);
196: return 4;
197: }
198: printf("return=%d registeredClient\n", (arr ? array_Size(arr) : 0));
199: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
200: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
201: rpc_cli_freeCall(&arr);
202:
203: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
204: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
205: rpc_cli_closeBLOBClient(&cli2);
206: rpc_cli_closeClient(&cli);
207: return 4;
208: }
209: printf("return=%d registeredBLOBClient\n", (arr ? array_Size(arr) : 0));
210: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
211: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
212: rpc_cli_freeCall(&arr);
213:
214: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_BLOBVARS, NULL, &arr) < 0) {
215: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
216: rpc_cli_closeBLOBClient(&cli2);
217: rpc_cli_closeClient(&cli);
218: return 5;
219: }
220: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
221: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
222: rpc_cli_freeCall(&arr);
223:
224: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCALLS, NULL, &arr) < 0) {
225: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
226: rpc_cli_closeBLOBClient(&cli2);
227: rpc_cli_closeClient(&cli);
228: return 5;
229: }
230: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
231: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
232: rpc_cli_freeCall(&arr);
233:
234: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVSESSIONS, NULL, &arr) < 0) {
235: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
236: rpc_cli_closeBLOBClient(&cli2);
237: rpc_cli_closeClient(&cli);
238: return 6;
239: }
240: printf("c=%d v=%p\n", array_Size(arr), arr);
241: printf("session(%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(array(arr, 0, ait_val_t*)),
242: AIT_GET_U8(array(arr, 1, ait_val_t*)), AIT_GET_I32(array(arr, 2, ait_val_t*)));
243: rpc_cli_freeCall(&arr);
244: #endif
245:
246: printf("shutdown rpc server? (y/n): ");
247: if (getchar() == 'y')
248: rpc_cli_execCall(cli, RPC_NOREPLY, CALL_SRVSHUTDOWN, NULL, NULL);
249:
250: rpc_cli_closeClient2(&cli);
251: return 0;
252: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>