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