Annotation of libaitrpc/example/tcli.c, revision 1.19.2.1
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);
1.19.2.1! misho 162: printf("cli_id=%d\n", cli->cli_id);
! 163: AIT_SET_I32(v, (cli->cli_id == SOCK_STREAM || cli->cli_id == SOCK_EXT) ? 50000 : 5000);
1.19 misho 164: if (rpc_cli_execCall(cli, RPC_REPLY, RC_big, valz, &arr) < 0) {
1.16 misho 165: printf("error:: \"big\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
166: } else
167: printf("return=%d big arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
168: ait_freeVars(&arr);
1.19 misho 169: ait_freeVars(&valz);
1.16 misho 170:
1.7 misho 171:
1.12 misho 172: valz = ait_allocVars(1);
173: v = array(valz, 0, ait_val_t*);
1.7 misho 174: AIT_SET_DATA(v, "1234567890", 11);
1.12 misho 175: array_Set(valz, 0, v);
1.8 misho 176: if (rpc_cli_execCall(cli, RPC_NOREPLY, RC_xxx, valz, &arr) < 0) {
1.7 misho 177: printf("0) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.12 misho 178: ait_freeVars(&valz);
1.7 misho 179: if (arr)
1.10 misho 180: rpc_cli_freeCall(&arr);
1.8 misho 181: rpc_cli_closeBLOBClient(&cli2);
182: rpc_cli_closeClient(&cli);
1.7 misho 183: return 3;
184: }
1.12 misho 185: printf("0) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
186: ait_freeVars(&valz);
1.7 misho 187: if (arr) {
188: printf("...REPLY --- ");
1.12 misho 189: v = array(arr, 0, ait_val_t*);
1.7 misho 190: printf("ret_val0:: %p %s len=%d type=%d\n",
191: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
1.10 misho 192: rpc_cli_freeCall(&arr);
1.7 misho 193: }
194:
1.12 misho 195: valz = ait_allocVars(1);
196: v = array(valz, 0, ait_val_t*);
1.7 misho 197: AIT_SET_DATA(v, "0987654321", 11);
1.12 misho 198: array_Set(valz, 0, v);
1.8 misho 199: if (rpc_cli_execCall(cli, RPC_REPLY, RC_xxx, valz, &arr) < 0) {
1.7 misho 200: printf("1) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.12 misho 201: ait_freeVars(&valz);
1.7 misho 202: if (arr)
1.10 misho 203: rpc_cli_freeCall(&arr);
1.8 misho 204: rpc_cli_closeBLOBClient(&cli2);
205: rpc_cli_closeClient(&cli);
1.7 misho 206: return 3;
207: }
1.12 misho 208: printf("1) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
209: ait_freeVars(&valz);
1.7 misho 210: if (arr) {
211: printf("@REPLY --- ");
1.12 misho 212: v = array(arr, 0, ait_val_t*);
1.7 misho 213: printf("ret_val0:: %p %s len=%d type=%d\n",
214: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
1.10 misho 215: rpc_cli_freeCall(&arr);
1.7 misho 216: }
217:
218:
1.8 misho 219: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 220: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.8 misho 221: rpc_cli_closeBLOBClient(&cli2);
222: rpc_cli_closeClient(&cli);
1.1 misho 223: return 4;
224: }
1.12 misho 225: printf("return=%d registeredClient\n", (arr ? array_Size(arr) : 0));
226: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
227: printf("registeredClient(%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_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 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.2 misho 234: return 4;
235: }
1.12 misho 236: printf("return=%d registeredBLOBClient\n", (arr ? array_Size(arr) : 0));
237: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
238: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
1.10 misho 239: rpc_cli_freeCall(&arr);
1.4 misho 240:
1.8 misho 241: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_BLOBVARS, NULL, &arr) < 0) {
1.2 misho 242: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.8 misho 243: rpc_cli_closeBLOBClient(&cli2);
244: rpc_cli_closeClient(&cli);
1.2 misho 245: return 5;
246: }
1.12 misho 247: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
248: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
1.10 misho 249: rpc_cli_freeCall(&arr);
1.4 misho 250:
1.8 misho 251: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCALLS, NULL, &arr) < 0) {
1.1 misho 252: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.8 misho 253: rpc_cli_closeBLOBClient(&cli2);
254: rpc_cli_closeClient(&cli);
1.1 misho 255: return 5;
256: }
1.12 misho 257: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
258: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
1.10 misho 259: rpc_cli_freeCall(&arr);
1.4 misho 260:
1.8 misho 261: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVSESSIONS, NULL, &arr) < 0) {
1.1 misho 262: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.8 misho 263: rpc_cli_closeBLOBClient(&cli2);
264: rpc_cli_closeClient(&cli);
1.1 misho 265: return 6;
266: }
1.12 misho 267: printf("c=%d v=%p\n", array_Size(arr), arr);
1.13 misho 268: printf("session(%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(array(arr, 0, ait_val_t*)),
269: AIT_GET_U8(array(arr, 1, ait_val_t*)), AIT_GET_I32(array(arr, 2, ait_val_t*)));
1.10 misho 270: rpc_cli_freeCall(&arr);
1.1 misho 271:
1.15 misho 272: printf("shutdown rpc server? (y/n): ");
273: if (getchar() == 'y')
1.8 misho 274: rpc_cli_execCall(cli, RPC_NOREPLY, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 275:
1.8 misho 276: rpc_cli_closeBLOBClient(&cli2);
277: rpc_cli_closeClient(&cli);
1.1 misho 278: return 0;
279: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>