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