Annotation of libaitrpc/example/tcli.c, revision 1.2.4.5
1.1 misho 1: #include <stdio.h>
1.2 misho 2: #include <pthread.h>
1.1 misho 3: #include <aitrpc.h>
4:
5: //rpc_val_t valz[3];
1.2.4.3 misho 6:
1.1 misho 7:
8: int main()
9: {
1.2 misho 10: rpc_cli_t *cli, *cli2;
1.1 misho 11: int c, i, ret;
1.2 misho 12: rpc_val_t tval, valz[3], *v = NULL;
13: char *mem, *blob43 = malloc(512);
1.1 misho 14:
1.2.4.3 misho 15: cli = rpc_cli_openClient(100, 2, AF_INET, "127.0.0.1", 11111);
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.4.3 misho 21: cli2 = rpc_cli_openBLOBClient(cli, 0);
1.2 misho 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:
30: RPC_SET_I32(&(valz[0]), 12345678);
31: RPC_SET_STR(&(valz[1]), "gniah_blah SHMINK!");
1.2 misho 32: RPC_SET_BLOB(&(valz[2]), 0, 512);
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
37: printf("Get BLOB = %x\n", RPC_GET_BLOB(&valz[2]));
38:
39: /* test case for unknown blob ...
40: RPC_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
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",
54: &v[0], RPC_GET_BUF(&v[0]), RPC_LEN_VAL(&v[0]), RPC_TYPE_VAL(&v[0]));
55: printf("ret_val1:: %d len=%d type=%d\n",
56: RPC_GET_I8(&v[1]), RPC_LEN_VAL(&v[1]), RPC_TYPE_VAL(&v[1]));
57: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
58: RPC_EMPTY_VAL(&v[2]), RPC_GET_STR(&v[2]), RPC_LEN_VAL(&v[2]), RPC_TYPE_VAL(&v[2]));
59: printf("ret_val3:: %X %d\n", RPC_GET_BLOB(&v[3]), RPC_LEN_VAL(&v[3]));
1.2.4.4 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.2.4.4 misho 63: printf("+++++++ BLOB=%s", mem);
1.2 misho 64: free(mem);
65: }
66: RPC_FREE_VAL(&v[0]);
67: RPC_FREE_VAL(&v[1]);
68: RPC_FREE_VAL(&v[2]);
69: RPC_FREE_VAL(&v[3]);
70: rpc_cli_freeVals(c, v);
71: }
1.1 misho 72: }
73: RPC_FREE_VAL(&valz[0]);
74: RPC_FREE_VAL(&valz[1]);
75: RPC_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.2 misho 89: printf("registeredClient(%d)=%s\n", i, RPC_GET_STR(&v[i]));
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++)
97: printf("registeredBLOBClient(%d)=%s\n", i, RPC_GET_STR(&*v));
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++)
105: printf("registeredBLOBVars(%d)=%0X\n", i, RPC_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++)
112: printf("registeredCall(%d)=%s\n", i, RPC_GET_STR(&v[i]));
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);
119: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) RPC_GET_U8(&v[0]), (uint32_t) RPC_GET_U32(&v[1]),
120: RPC_GET_U32(&v[2]), RPC_GET_I32(&v[3]));
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>