Annotation of libaitrpc/example/tcli.c, revision 1.6.2.5
1.1 misho 1: #include <stdio.h>
1.2 misho 2: #include <pthread.h>
1.1 misho 3: #include <aitrpc.h>
4:
1.4 misho 5: //ait_val_t valz[3];
1.1 misho 6:
1.3 misho 7:
1.1 misho 8: int main()
9: {
1.2 misho 10: rpc_cli_t *cli, *cli2;
1.1 misho 11: int c, i, ret;
1.4 misho 12: ait_val_t tval, *v = NULL;
13: array_t *valz, *arr;
1.2 misho 14: char *mem, *blob43 = malloc(512);
1.1 misho 15:
1.6 misho 16: cli = rpc_cli_openClient(100, 2, 1024 * 10, 0, AF_INET, "127.0.0.1", 11111);
1.3 misho 17: // cli = rpc_cli_openClient(100, 2, AF_LOCAL, "0.0.0.0", 11111);
1.1 misho 18: if (!cli) {
19: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.4 misho 20: free(blob43);
1.1 misho 21: return 1;
22: }
1.4 misho 23:
1.2 misho 24: cli2 = rpc_cli_openBLOBClient(cli, 0);
25: if (!cli2) {
26: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.4 misho 27: rpc_cli_closeClient(cli);
28: free(blob43);
1.2 misho 29: return 1;
30: }
31:
32: memset(blob43, 0, 512);
33: strlcpy(blob43, "aaaaaaaaaaaaaaa cddddddddddddddd zzzzzzzzzzzzzzzzzzzzz !!!!\n\n\n675675676...\n", 512);
1.1 misho 34:
1.5 misho 35: valz = io_allocVars(3);
1.4 misho 36: v = io_array(valz, 0, ait_val_t*);
37: AIT_SET_I32(v, 12345678);
38: v = io_array(valz, 1, ait_val_t*);
39: AIT_SET_STR(v, "gniah_blah SHMINK!");
40: v = io_array(valz, 2, ait_val_t*);
41: AIT_NEW_BLOB(v, 512);
42: if (rpc_cli_sendBLOB(cli2, v, blob43) == -1) {
1.2 misho 43: printf("!!!!! blob error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.4 misho 44: rpc_cli_closeBLOBClient(cli2);
45: rpc_cli_closeClient(cli);
46: free(blob43);
1.2 misho 47: return 2;
48: } else
1.4 misho 49: printf("Get BLOB = %x\n", AIT_GET_BLOB(v));
1.2 misho 50:
51: /* test case for unknown blob ...
1.4 misho 52: AIT_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
1.2 misho 53: printf("test not found blob=%d\n", rpc_cli_getBLOB(cli2, &tval, (void**) &mem));
54: if (mem)
55: free(mem);
56: */
57:
1.1 misho 58: // for (i = 0; i < 1000000; i++)
1.6.2.2 misho 59: if ((ret = rpc_cli_execCall(cli, RPC_REPLY, NULL, "BBB", valz, &arr)) < 0) {
1.1 misho 60: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.4 misho 61: rpc_cli_closeBLOBClient(cli2);
62: rpc_cli_closeClient(cli);
63: free(blob43);
1.1 misho 64: return 2;
65: } else {
66: printf("ret=%d\n", ret);
1.4 misho 67: if (arr) {
68: v = io_array(arr, 0, ait_val_t*);
1.2 misho 69: printf("ret_val0:: %p %s len=%d type=%d\n",
1.4 misho 70: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
71: v = io_array(arr, 1, ait_val_t*);
1.2 misho 72: printf("ret_val1:: %d len=%d type=%d\n",
1.4 misho 73: AIT_GET_I8(v), AIT_LEN(v), AIT_TYPE(v));
74: v = io_array(arr, 2, ait_val_t*);
1.2 misho 75: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
1.4 misho 76: AIT_ISEMPTY(v), AIT_GET_STR(v), AIT_LEN(v), AIT_TYPE(v));
77: v = io_array(arr, 3, ait_val_t*);
78: printf("ret_val3:: %X %d\n", AIT_GET_BLOB(v), AIT_LEN(v));
79: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, v, (void**) &mem));
80: // printf("+++++++++ test found blob=%d\n", rpc_cli_recvBLOB(cli2, v, (void**) &mem));
1.2 misho 81: if (mem) {
1.3 misho 82: printf("+++++++ BLOB=%s", mem);
1.2 misho 83: free(mem);
84: }
1.5 misho 85: io_freeVars(&arr);
1.2 misho 86: }
1.1 misho 87: }
1.5 misho 88: io_freeVars(&valz);
1.2 misho 89: free(blob43);
1.1 misho 90:
1.6.2.2 misho 91: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, "aaa", NULL, &arr) < 0) {
1.4 misho 92: printf("error:: \"aaa\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.1 misho 93: return 3;
94: }
1.4 misho 95: printf("return=%d aaa arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
1.1 misho 96:
1.6.2.3 misho 97:
1.6.2.1 misho 98: valz = io_allocVars(1);
99: v = io_array(valz, 0, ait_val_t*);
100: AIT_SET_DATA(v, "1234567890", 11);
101: io_arraySet(valz, 0, v);
1.6.2.2 misho 102: if (rpc_cli_execCall(cli, RPC_NOREPLY, NULL, "xxx", valz, &arr) < 0) {
1.6.2.5 ! misho 103: printf("0) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 104: io_freeVars(&valz);
! 105: if (arr)
! 106: io_freeVars(&arr);
! 107: rpc_cli_closeBLOBClient(cli2);
! 108: rpc_cli_closeClient(cli);
1.6.2.1 misho 109: return 3;
110: }
1.6.2.5 ! misho 111: printf("0) return=%d xxx arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
1.6.2.3 misho 112: io_freeVars(&valz);
113: if (arr) {
114: printf("...REPLY --- ");
115: v = io_array(arr, 0, ait_val_t*);
116: printf("ret_val0:: %p %s len=%d type=%d\n",
117: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
118: io_freeVars(&arr);
119: }
120:
121: valz = io_allocVars(1);
122: v = io_array(valz, 0, ait_val_t*);
123: AIT_SET_DATA(v, "0987654321", 11);
124: io_arraySet(valz, 0, v);
125: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, "xxx", valz, &arr) < 0) {
1.6.2.5 ! misho 126: printf("1) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 127: io_freeVars(&valz);
! 128: if (arr)
! 129: io_freeVars(&arr);
! 130: rpc_cli_closeBLOBClient(cli2);
! 131: rpc_cli_closeClient(cli);
1.6.2.3 misho 132: return 3;
133: }
1.6.2.5 ! misho 134: printf("1) return=%d xxx arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
1.6.2.3 misho 135: io_freeVars(&valz);
136: if (arr) {
137: printf("@REPLY --- ");
138: v = io_array(arr, 0, ait_val_t*);
139: printf("ret_val0:: %p %s len=%d type=%d\n",
140: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
141: io_freeVars(&arr);
142: }
143:
1.6.2.1 misho 144:
1.6.2.2 misho 145: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 146: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.5 ! misho 147: rpc_cli_closeBLOBClient(cli2);
! 148: rpc_cli_closeClient(cli);
1.1 misho 149: return 4;
150: }
1.4 misho 151: printf("return=%d registeredClient\n", (arr ? io_arraySize(arr) : 0));
152: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
153: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 154: io_freeVars(&arr);
1.4 misho 155:
1.6.2.2 misho 156: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 misho 157: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.5 ! misho 158: rpc_cli_closeBLOBClient(cli2);
! 159: rpc_cli_closeClient(cli);
1.2 misho 160: return 4;
161: }
1.4 misho 162: printf("return=%d registeredBLOBClient\n", (arr ? io_arraySize(arr) : 0));
163: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
164: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 165: io_freeVars(&arr);
1.4 misho 166:
1.6.2.2 misho 167: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_BLOBVARS, NULL, &arr) < 0) {
1.2 misho 168: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.5 ! misho 169: rpc_cli_closeBLOBClient(cli2);
! 170: rpc_cli_closeClient(cli);
1.2 misho 171: return 5;
172: }
1.4 misho 173: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
174: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 175: io_freeVars(&arr);
1.4 misho 176:
1.6.2.2 misho 177: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_SRVCALLS, NULL, &arr) < 0) {
1.1 misho 178: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.5 ! misho 179: rpc_cli_closeBLOBClient(cli2);
! 180: rpc_cli_closeClient(cli);
1.1 misho 181: return 5;
182: }
1.4 misho 183: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
184: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 185: io_freeVars(&arr);
1.4 misho 186:
1.6.2.2 misho 187: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_SRVSESSIONS, NULL, &arr) < 0) {
1.1 misho 188: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.6.2.5 ! misho 189: rpc_cli_closeBLOBClient(cli2);
! 190: rpc_cli_closeClient(cli);
1.1 misho 191: return 6;
192: }
1.4 misho 193: printf("c=%d v=%p\n", io_arraySize(arr), arr);
194: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(io_array(arr, 0, ait_val_t*)),
195: (uint32_t) AIT_GET_U32(io_array(arr, 1, ait_val_t*)),
196: AIT_GET_U32(io_array(arr, 2, ait_val_t*)), AIT_GET_I32(io_array(arr, 3, ait_val_t*)));
1.5 misho 197: io_freeVars(&arr);
1.1 misho 198:
1.6.2.2 misho 199: rpc_cli_execCall(cli, RPC_NOREPLY, NULL, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 200:
201: rpc_cli_closeBLOBClient(cli2);
1.1 misho 202: rpc_cli_closeClient(cli);
203: return 0;
204: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>