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