Annotation of libaitrpc/example/tcli.c, revision 1.5.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.5.2.2 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.2.2 misho 32: valz = io_allocVars(2);
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.4 misho 53: if ((ret = rpc_cli_execCall(cli, 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.4 misho 82: if (rpc_cli_execCall(cli, NULL, "aaa", NULL, &arr) < 0) {
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.4 misho 88: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 89: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
90: return 4;
91: }
1.4 misho 92: printf("return=%d registeredClient\n", (arr ? io_arraySize(arr) : 0));
93: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
94: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 95: io_freeVars(&arr);
1.4 misho 96:
97: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 misho 98: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
99: return 4;
100: }
1.4 misho 101: printf("return=%d registeredBLOBClient\n", (arr ? io_arraySize(arr) : 0));
102: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
103: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 104: io_freeVars(&arr);
1.4 misho 105:
106: if (rpc_cli_execCall(cli, NULL, CALL_BLOBVARS, NULL, &arr) < 0) {
1.2 misho 107: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
108: return 5;
109: }
1.4 misho 110: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
111: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 112: io_freeVars(&arr);
1.4 misho 113:
114: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, NULL, &arr) < 0) {
1.1 misho 115: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
116: return 5;
117: }
1.4 misho 118: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
119: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 120: io_freeVars(&arr);
1.4 misho 121:
122: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, NULL, &arr) < 0) {
1.1 misho 123: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
124: return 6;
125: }
1.4 misho 126: printf("c=%d v=%p\n", io_arraySize(arr), arr);
127: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(io_array(arr, 0, ait_val_t*)),
128: (uint32_t) AIT_GET_U32(io_array(arr, 1, ait_val_t*)),
129: AIT_GET_U32(io_array(arr, 2, ait_val_t*)), AIT_GET_I32(io_array(arr, 3, ait_val_t*)));
1.5 misho 130: io_freeVars(&arr);
1.1 misho 131:
1.4 misho 132: rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 133:
134: rpc_cli_closeBLOBClient(cli2);
1.1 misho 135: rpc_cli_closeClient(cli);
136: return 0;
137: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>