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