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