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