Annotation of libaitrpc/example/tcli.c, revision 1.15.2.3
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());
155: return 3;
156: }
157: printf("return=%d big arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
158: ait_freeVars(&arr);
159:
1.7 misho 160:
1.12 misho 161: valz = ait_allocVars(1);
162: v = array(valz, 0, ait_val_t*);
1.7 misho 163: AIT_SET_DATA(v, "1234567890", 11);
1.12 misho 164: array_Set(valz, 0, v);
1.8 misho 165: if (rpc_cli_execCall(cli, RPC_NOREPLY, RC_xxx, valz, &arr) < 0) {
1.7 misho 166: printf("0) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.12 misho 167: ait_freeVars(&valz);
1.7 misho 168: if (arr)
1.10 misho 169: rpc_cli_freeCall(&arr);
1.8 misho 170: rpc_cli_closeBLOBClient(&cli2);
171: rpc_cli_closeClient(&cli);
1.7 misho 172: return 3;
173: }
1.12 misho 174: printf("0) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
175: ait_freeVars(&valz);
1.7 misho 176: if (arr) {
177: printf("...REPLY --- ");
1.12 misho 178: v = array(arr, 0, ait_val_t*);
1.7 misho 179: printf("ret_val0:: %p %s len=%d type=%d\n",
180: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
1.10 misho 181: rpc_cli_freeCall(&arr);
1.7 misho 182: }
183:
1.12 misho 184: valz = ait_allocVars(1);
185: v = array(valz, 0, ait_val_t*);
1.7 misho 186: AIT_SET_DATA(v, "0987654321", 11);
1.12 misho 187: array_Set(valz, 0, v);
1.8 misho 188: if (rpc_cli_execCall(cli, RPC_REPLY, RC_xxx, valz, &arr) < 0) {
1.7 misho 189: printf("1) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.12 misho 190: ait_freeVars(&valz);
1.7 misho 191: if (arr)
1.10 misho 192: rpc_cli_freeCall(&arr);
1.8 misho 193: rpc_cli_closeBLOBClient(&cli2);
194: rpc_cli_closeClient(&cli);
1.7 misho 195: return 3;
196: }
1.12 misho 197: printf("1) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
198: ait_freeVars(&valz);
1.7 misho 199: if (arr) {
200: printf("@REPLY --- ");
1.12 misho 201: v = array(arr, 0, ait_val_t*);
1.7 misho 202: printf("ret_val0:: %p %s len=%d type=%d\n",
203: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
1.10 misho 204: rpc_cli_freeCall(&arr);
1.7 misho 205: }
206:
207:
1.8 misho 208: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 209: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.8 misho 210: rpc_cli_closeBLOBClient(&cli2);
211: rpc_cli_closeClient(&cli);
1.1 misho 212: return 4;
213: }
1.12 misho 214: printf("return=%d registeredClient\n", (arr ? array_Size(arr) : 0));
215: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
216: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
1.10 misho 217: rpc_cli_freeCall(&arr);
1.4 misho 218:
1.8 misho 219: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 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.2 misho 223: return 4;
224: }
1.12 misho 225: printf("return=%d registeredBLOBClient\n", (arr ? array_Size(arr) : 0));
226: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
227: printf("registeredBLOBClient(%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_BLOBVARS, 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 5;
235: }
1.12 misho 236: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
237: printf("registeredBLOBVars(%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_SRVCALLS, 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 5;
245: }
1.12 misho 246: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
247: printf("registeredCall(%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_SRVSESSIONS, 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 6;
255: }
1.12 misho 256: printf("c=%d v=%p\n", array_Size(arr), arr);
1.13 misho 257: printf("session(%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(array(arr, 0, ait_val_t*)),
258: AIT_GET_U8(array(arr, 1, ait_val_t*)), AIT_GET_I32(array(arr, 2, ait_val_t*)));
1.10 misho 259: rpc_cli_freeCall(&arr);
1.1 misho 260:
1.15 misho 261: printf("shutdown rpc server? (y/n): ");
262: if (getchar() == 'y')
1.8 misho 263: rpc_cli_execCall(cli, RPC_NOREPLY, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 264:
1.8 misho 265: rpc_cli_closeBLOBClient(&cli2);
266: rpc_cli_closeClient(&cli);
1.1 misho 267: return 0;
268: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>