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