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