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