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