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