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