Annotation of libaitrpc/example/tcli.c, revision 1.5.2.1
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.4 misho 16: cli = rpc_cli_openClient(100, 2, 1024 * 10, 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.5.2.1 ! misho 23: #if 0
1.2 misho 24: cli2 = rpc_cli_openBLOBClient(cli, 0);
25: if (!cli2) {
26: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
27: return 1;
28: }
29:
30: memset(blob43, 0, 512);
31: strlcpy(blob43, "aaaaaaaaaaaaaaa cddddddddddddddd zzzzzzzzzzzzzzzzzzzzz !!!!\n\n\n675675676...\n", 512);
1.1 misho 32:
1.5 misho 33: valz = io_allocVars(3);
1.4 misho 34: v = io_array(valz, 0, ait_val_t*);
35: AIT_SET_I32(v, 12345678);
36: v = io_array(valz, 1, ait_val_t*);
37: AIT_SET_STR(v, "gniah_blah SHMINK!");
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.4 misho 54: if ((ret = rpc_cli_execCall(cli, NULL, "BBB", valz, &arr)) < 0) {
1.1 misho 55: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
56: return 2;
57: } else {
58: printf("ret=%d\n", ret);
1.4 misho 59: if (arr) {
60: v = io_array(arr, 0, ait_val_t*);
1.2 misho 61: printf("ret_val0:: %p %s len=%d type=%d\n",
1.4 misho 62: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
63: v = io_array(arr, 1, ait_val_t*);
1.2 misho 64: printf("ret_val1:: %d len=%d type=%d\n",
1.4 misho 65: AIT_GET_I8(v), AIT_LEN(v), AIT_TYPE(v));
66: v = io_array(arr, 2, ait_val_t*);
1.2 misho 67: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
1.4 misho 68: AIT_ISEMPTY(v), AIT_GET_STR(v), AIT_LEN(v), AIT_TYPE(v));
69: v = io_array(arr, 3, ait_val_t*);
70: printf("ret_val3:: %X %d\n", AIT_GET_BLOB(v), AIT_LEN(v));
71: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, v, (void**) &mem));
72: // printf("+++++++++ test found blob=%d\n", rpc_cli_recvBLOB(cli2, v, (void**) &mem));
1.2 misho 73: if (mem) {
1.3 misho 74: printf("+++++++ BLOB=%s", mem);
1.2 misho 75: free(mem);
76: }
1.5 misho 77: io_freeVars(&arr);
1.2 misho 78: }
1.1 misho 79: }
1.5 misho 80: io_freeVars(&valz);
1.2 misho 81: free(blob43);
1.1 misho 82:
1.4 misho 83: if (rpc_cli_execCall(cli, NULL, "aaa", NULL, &arr) < 0) {
84: printf("error:: \"aaa\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
1.1 misho 85: return 3;
86: }
1.4 misho 87: printf("return=%d aaa arr=%p\n", arr ? io_arraySize(arr) : 42424242, arr);
1.1 misho 88:
1.4 misho 89: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, NULL, &arr) < 0) {
1.1 misho 90: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
91: return 4;
92: }
1.4 misho 93: printf("return=%d registeredClient\n", (arr ? io_arraySize(arr) : 0));
94: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
95: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 96: io_freeVars(&arr);
1.4 misho 97:
98: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
1.2 misho 99: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
100: return 4;
101: }
1.4 misho 102: printf("return=%d registeredBLOBClient\n", (arr ? io_arraySize(arr) : 0));
103: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
104: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 105: io_freeVars(&arr);
1.4 misho 106:
107: if (rpc_cli_execCall(cli, NULL, CALL_BLOBVARS, NULL, &arr) < 0) {
1.2 misho 108: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
109: return 5;
110: }
1.4 misho 111: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
112: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 113: io_freeVars(&arr);
1.4 misho 114:
115: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, NULL, &arr) < 0) {
1.1 misho 116: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
117: return 5;
118: }
1.4 misho 119: for (i = 0; i < (arr ? io_arraySize(arr) : 0); i++)
120: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(io_array(arr, i, ait_val_t*)));
1.5 misho 121: io_freeVars(&arr);
1.4 misho 122:
123: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, NULL, &arr) < 0) {
1.1 misho 124: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
125: return 6;
126: }
1.4 misho 127: printf("c=%d v=%p\n", io_arraySize(arr), arr);
128: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(io_array(arr, 0, ait_val_t*)),
129: (uint32_t) AIT_GET_U32(io_array(arr, 1, ait_val_t*)),
130: AIT_GET_U32(io_array(arr, 2, ait_val_t*)), AIT_GET_I32(io_array(arr, 3, ait_val_t*)));
1.5 misho 131: io_freeVars(&arr);
1.1 misho 132:
1.4 misho 133: rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, NULL, NULL);
1.2 misho 134:
135: rpc_cli_closeBLOBClient(cli2);
1.5.2.1 ! misho 136: #endif
1.1 misho 137: rpc_cli_closeClient(cli);
138: return 0;
139: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>