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