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