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