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