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