Annotation of libaitrpc/example/tcli.c, revision 1.6.2.4
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.1 misho 103: printf("error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
104: return 3;
105: }
106: printf("return=%d xxx arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
1.6.2.3 misho 107: io_freeVars(&valz);
108: if (arr) {
109: printf("...REPLY --- ");
110: v = io_array(arr, 0, ait_val_t*);
111: printf("ret_val0:: %p %s len=%d type=%d\n",
112: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
113: io_freeVars(&arr);
114: }
115:
116: valz = io_allocVars(1);
117: v = io_array(valz, 0, ait_val_t*);
118: AIT_SET_DATA(v, "0987654321", 11);
119: io_arraySet(valz, 0, v);
120: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, "xxx", valz, &arr) < 0) {
121: printf("error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
122: return 3;
123: }
124: printf("return=%d xxx arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
125: io_freeVars(&valz);
126: if (arr) {
127: printf("@REPLY --- ");
128: v = io_array(arr, 0, ait_val_t*);
129: printf("ret_val0:: %p %s len=%d type=%d\n",
130: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
131: io_freeVars(&arr);
132: }
133:
1.6.2.1 misho 134:
1.6.2.2 misho 135: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 136: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
137: return 4;
138: }
1.4 misho 139: printf("return=%d registeredClient\n", (arr ? io_arraySize(arr) : 0));
140: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
141: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 142: io_freeVars(&arr);
1.4 misho 143:
1.6.2.2 misho 144: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 misho 145: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
146: return 4;
147: }
1.4 misho 148: printf("return=%d registeredBLOBClient\n", (arr ? io_arraySize(arr) : 0));
149: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
150: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 151: io_freeVars(&arr);
1.4 misho 152:
1.6.2.2 misho 153: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_BLOBVARS, NULL, &arr) < 0) {
1.2 misho 154: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
155: return 5;
156: }
1.4 misho 157: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
158: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 159: io_freeVars(&arr);
1.4 misho 160:
1.6.2.2 misho 161: if (rpc_cli_execCall(cli, RPC_REPLY, NULL, CALL_SRVCALLS, NULL, &arr) < 0) {
1.1 misho 162: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
163: return 5;
164: }
1.4 misho 165: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
166: printf("registeredCall(%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_SRVSESSIONS, NULL, &arr) < 0) {
1.1 misho 170: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
171: return 6;
172: }
1.4 misho 173: printf("c=%d v=%p\n", io_arraySize(arr), arr);
174: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(io_array(arr, 0, ait_val_t*)),
175: (uint32_t) AIT_GET_U32(io_array(arr, 1, ait_val_t*)),
176: AIT_GET_U32(io_array(arr, 2, ait_val_t*)), AIT_GET_I32(io_array(arr, 3, ait_val_t*)));
1.5 misho 177: io_freeVars(&arr);
1.1 misho 178:
1.6.2.2 misho 179: rpc_cli_execCall(cli, RPC_NOREPLY, NULL, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 180:
181: rpc_cli_closeBLOBClient(cli2);
1.1 misho 182: rpc_cli_closeClient(cli);
183: return 0;
184: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>