Annotation of libaitrpc/example/tcli.c, revision 1.1.1.1.2.7
1.1 misho 1: #include <stdio.h>
2: #include <aitrpc.h>
3:
4: //rpc_val_t valz[3];
5:
6: int main()
7: {
1.1.1.1.2.4 misho 8: rpc_cli_t *cli, *cli2;
1.1 misho 9: int c, i, ret;
1.1.1.1.2.6 misho 10: rpc_val_t tval, valz[3], *v = NULL;
11: char *mem, *blob43 = malloc(512);
1.1 misho 12:
13: cli = rpc_cli_openClient(100, 2, 2, "127.0.0.1", 11111);
14: if (!cli) {
15: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
16: return 1;
17: }
1.1.1.1.2.4 misho 18: cli2 = rpc_cli_openBLOBClient(cli, 0);
19: if (!cli2) {
20: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
21: return 1;
22: }
1.1 misho 23:
1.1.1.1.2.5 misho 24: memset(blob43, 0, 512);
1.1.1.1.2.3 misho 25: strlcpy(blob43, "aaaaaaaaaaaaaaa cddddddddddddddd zzzzzzzzzzzzzzzzzzzzz !!!!\n\n\n675675676...\n", 512);
26:
1.1 misho 27: RPC_SET_I32(&(valz[0]), 12345678);
28: RPC_SET_STR(&(valz[1]), "gniah_blah SHMINK!");
1.1.1.1.2.6 misho 29: RPC_SET_BLOB(&(valz[2]), 0, 512);
1.1.1.1.2.4 misho 30: if (rpc_cli_sendBLOB(cli2, &valz[2], blob43) == -1) {
31: printf("!!!!! blob error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
32: return 2;
1.1.1.1.2.5 misho 33: } else
34: printf("Get BLOB = %x\n", RPC_GET_BLOB(&valz[2]));
1.1.1.1.2.4 misho 35:
1.1.1.1.2.6 misho 36: RPC_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
37: printf("test not found blob=%d\n", rpc_cli_recvBLOB(cli2, &tval, (void**) &mem));
38: if (mem)
39: free(mem);
40:
1.1 misho 41: // for (i = 0; i < 1000000; i++)
42: if ((ret = rpc_cli_execCall(cli, NULL, "BBB", 3, valz, &c, &v)) < 0) {
43: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
44: return 2;
45: } else {
46: printf("ret=%d\n", ret);
1.1.1.1.2.2 misho 47: if (c && v) {
48: printf("ret_val0:: %p %s len=%d type=%d\n",
49: &v[0], RPC_GET_BUF(&v[0]), RPC_LEN_VAL(&v[0]), RPC_TYPE_VAL(&v[0]));
50: printf("ret_val1:: %d len=%d type=%d\n",
51: RPC_GET_I8(&v[1]), RPC_LEN_VAL(&v[1]), RPC_TYPE_VAL(&v[1]));
52: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
53: RPC_EMPTY_VAL(&v[2]), RPC_GET_STR(&v[2]), RPC_LEN_VAL(&v[2]), RPC_TYPE_VAL(&v[2]));
1.1.1.1.2.6 misho 54: printf("test found blob=%d %X\n", rpc_cli_recvBLOB(cli2, &v[3], (void**) &mem),
55: RPC_GET_BLOB(&v[3]));
56: if (mem) {
57: printf("BLOB=%s", mem);
58: free(mem);
59: }
1.1.1.1.2.2 misho 60: RPC_FREE_VAL(&v[0]);
61: RPC_FREE_VAL(&v[1]);
62: RPC_FREE_VAL(&v[2]);
1.1.1.1.2.6 misho 63: RPC_FREE_VAL(&v[3]);
1.1.1.1.2.2 misho 64: rpc_cli_freeVals(c, v);
65: }
1.1 misho 66: }
67: RPC_FREE_VAL(&valz[0]);
68: RPC_FREE_VAL(&valz[1]);
69: RPC_FREE_VAL(&valz[2]);
1.1.1.1.2.3 misho 70: free(blob43);
1.1 misho 71:
72: if (rpc_cli_execCall(cli, NULL, "aaa", 0, NULL, &c, &v) < 0) {
73: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
74: return 3;
75: }
76:
77: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, 0, NULL, &c, &v) < 0) {
78: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
79: return 4;
80: }
1.1.1.1.2.3 misho 81: printf("return=%d registeredClient\n", c);
1.1 misho 82: for (i = 0; i < c; i++)
1.1.1.1.2.3 misho 83: printf("registeredClient(%d)=%s\n", i, RPC_GET_STR(&v[i]));
1.1 misho 84: rpc_cli_freeVals(c, v);
1.1.1.1.2.3 misho 85: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, 0, NULL, &c, &v) < 0) {
86: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
87: return 4;
88: }
89: printf("return=%d registeredBLOBClient\n", c);
90: for (i = 0; i < c; i++)
91: printf("registeredBLOBClient(%d)=%s\n", i, RPC_GET_STR(&*v));
92: rpc_cli_freeVals(c, v);
93:
1.1.1.1.2.6 misho 94: if (rpc_cli_execCall(cli, NULL, CALL_BLOBVARS, 0, NULL, &c, &v) < 0) {
95: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
96: return 5;
97: }
98: for (i = 0; i < c; i++)
99: printf("registeredBLOBVars(%d)=%0X\n", i, RPC_GET_U32(&v[i]));
100: rpc_cli_freeVals(c, v);
1.1 misho 101: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, 0, NULL, &c, &v) < 0) {
102: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
103: return 5;
104: }
105: for (i = 0; i < c; i++)
106: printf("registeredCall(%d)=%s\n", i, RPC_GET_STR(&v[i]));
107: rpc_cli_freeVals(c, v);
108: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, 0, NULL, &c, &v) < 0) {
109: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
110: return 6;
111: }
112: printf("c=%d v=%p\n", c, v);
113: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) RPC_GET_U8(&v[0]), (uint32_t) RPC_GET_U32(&v[1]),
114: RPC_GET_U32(&v[2]), RPC_GET_I32(&v[3]));
115: rpc_cli_freeVals(c, v);
116:
1.1.1.1.2.3 misho 117: // rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, 0, NULL, 0, NULL);
1.1.1.1.2.1 misho 118:
1.1.1.1.2.4 misho 119: rpc_cli_closeBLOBClient(cli2);
1.1 misho 120: rpc_cli_closeClient(cli);
121: return 0;
122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>