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