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