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