Annotation of libaitrpc/example/tcli.c, revision 1.5.2.2
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!");
1.5.2.2 ! misho 37: #if 0
1.4 misho 38: v = io_array(valz, 2, ait_val_t*);
39: AIT_NEW_BLOB(v, 512);
40: if (rpc_cli_sendBLOB(cli2, v, blob43) == -1) {
1.2 misho 41: printf("!!!!! blob error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
42: return 2;
43: } else
1.4 misho 44: printf("Get BLOB = %x\n", AIT_GET_BLOB(v));
1.2 misho 45:
46: /* test case for unknown blob ...
1.4 misho 47: AIT_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
1.2 misho 48: printf("test not found blob=%d\n", rpc_cli_getBLOB(cli2, &tval, (void**) &mem));
49: if (mem)
50: free(mem);
51: */
52:
1.1 misho 53: // for (i = 0; i < 1000000; i++)
1.5.2.2 ! misho 54: #endif
1.4 misho 55: if ((ret = rpc_cli_execCall(cli, NULL, "BBB", valz, &arr)) < 0) {
1.1 misho 56: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
57: return 2;
58: } else {
59: printf("ret=%d\n", ret);
1.4 misho 60: if (arr) {
61: v = io_array(arr, 0, ait_val_t*);
1.2 misho 62: printf("ret_val0:: %p %s len=%d type=%d\n",
1.4 misho 63: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
64: v = io_array(arr, 1, ait_val_t*);
1.2 misho 65: printf("ret_val1:: %d len=%d type=%d\n",
1.4 misho 66: AIT_GET_I8(v), AIT_LEN(v), AIT_TYPE(v));
67: v = io_array(arr, 2, ait_val_t*);
1.2 misho 68: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
1.4 misho 69: AIT_ISEMPTY(v), AIT_GET_STR(v), AIT_LEN(v), AIT_TYPE(v));
1.5.2.2 ! misho 70: #if 0
1.4 misho 71: v = io_array(arr, 3, ait_val_t*);
72: printf("ret_val3:: %X %d\n", AIT_GET_BLOB(v), AIT_LEN(v));
73: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, v, (void**) &mem));
74: // printf("+++++++++ test found blob=%d\n", rpc_cli_recvBLOB(cli2, v, (void**) &mem));
1.2 misho 75: if (mem) {
1.3 misho 76: printf("+++++++ BLOB=%s", mem);
1.2 misho 77: free(mem);
78: }
1.5.2.2 ! misho 79: #endif
1.5 misho 80: io_freeVars(&arr);
1.2 misho 81: }
1.1 misho 82: }
1.5 misho 83: io_freeVars(&valz);
1.2 misho 84: free(blob43);
1.1 misho 85:
1.4 misho 86: if (rpc_cli_execCall(cli, NULL, "aaa", NULL, &arr) < 0) {
87: printf("error:: \"aaa\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.1 misho 88: return 3;
89: }
1.4 misho 90: printf("return=%d aaa arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
1.1 misho 91:
1.4 misho 92: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 93: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
94: return 4;
95: }
1.4 misho 96: printf("return=%d registeredClient\n", (arr ? io_arraySize(arr) : 0));
97: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
98: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 99: io_freeVars(&arr);
1.4 misho 100:
101: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 misho 102: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
103: return 4;
104: }
1.4 misho 105: printf("return=%d registeredBLOBClient\n", (arr ? io_arraySize(arr) : 0));
106: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
107: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 108: io_freeVars(&arr);
1.4 misho 109:
110: if (rpc_cli_execCall(cli, NULL, CALL_BLOBVARS, NULL, &arr) < 0) {
1.2 misho 111: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
112: return 5;
113: }
1.4 misho 114: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
115: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 116: io_freeVars(&arr);
1.4 misho 117:
118: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, NULL, &arr) < 0) {
1.1 misho 119: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
120: return 5;
121: }
1.4 misho 122: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
123: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 124: io_freeVars(&arr);
1.4 misho 125:
126: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, NULL, &arr) < 0) {
1.1 misho 127: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
128: return 6;
129: }
1.4 misho 130: printf("c=%d v=%p\n", io_arraySize(arr), arr);
131: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(io_array(arr, 0, ait_val_t*)),
132: (uint32_t) AIT_GET_U32(io_array(arr, 1, ait_val_t*)),
133: AIT_GET_U32(io_array(arr, 2, ait_val_t*)), AIT_GET_I32(io_array(arr, 3, ait_val_t*)));
1.5 misho 134: io_freeVars(&arr);
1.1 misho 135:
1.4 misho 136: rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 137:
138: rpc_cli_closeBLOBClient(cli2);
1.1 misho 139: rpc_cli_closeClient(cli);
140: return 0;
141: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>