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