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