Annotation of libaitrpc/example/tcli.c, revision 1.1.1.1.2.5
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;
10: rpc_val_t valz[3], *v = NULL;
1.1.1.1.2.3 misho 11: char *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.5! misho 29: RPC_SET_BLOB(&(valz[2]), 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 misho 36: // for (i = 0; i < 1000000; i++)
37: if ((ret = rpc_cli_execCall(cli, NULL, "BBB", 3, valz, &c, &v)) < 0) {
38: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
39: return 2;
40: } else {
41: printf("ret=%d\n", ret);
1.1.1.1.2.2 misho 42: if (c && v) {
43: printf("ret_val0:: %p %s len=%d type=%d\n",
44: &v[0], RPC_GET_BUF(&v[0]), RPC_LEN_VAL(&v[0]), RPC_TYPE_VAL(&v[0]));
45: printf("ret_val1:: %d len=%d type=%d\n",
46: RPC_GET_I8(&v[1]), RPC_LEN_VAL(&v[1]), RPC_TYPE_VAL(&v[1]));
47: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
48: RPC_EMPTY_VAL(&v[2]), RPC_GET_STR(&v[2]), RPC_LEN_VAL(&v[2]), RPC_TYPE_VAL(&v[2]));
49: RPC_FREE_VAL(&v[0]);
50: RPC_FREE_VAL(&v[1]);
51: RPC_FREE_VAL(&v[2]);
52: rpc_cli_freeVals(c, v);
53: }
1.1 misho 54: }
55: RPC_FREE_VAL(&valz[0]);
56: RPC_FREE_VAL(&valz[1]);
57: RPC_FREE_VAL(&valz[2]);
1.1.1.1.2.3 misho 58: free(blob43);
1.1 misho 59:
60: if (rpc_cli_execCall(cli, NULL, "aaa", 0, NULL, &c, &v) < 0) {
61: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
62: return 3;
63: }
64:
65: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, 0, NULL, &c, &v) < 0) {
66: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
67: return 4;
68: }
1.1.1.1.2.3 misho 69: printf("return=%d registeredClient\n", c);
1.1 misho 70: for (i = 0; i < c; i++)
1.1.1.1.2.3 misho 71: printf("registeredClient(%d)=%s\n", i, RPC_GET_STR(&v[i]));
1.1 misho 72: rpc_cli_freeVals(c, v);
1.1.1.1.2.3 misho 73: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, 0, NULL, &c, &v) < 0) {
74: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
75: return 4;
76: }
77: printf("return=%d registeredBLOBClient\n", c);
78: for (i = 0; i < c; i++)
79: printf("registeredBLOBClient(%d)=%s\n", i, RPC_GET_STR(&*v));
80: rpc_cli_freeVals(c, v);
81:
1.1 misho 82: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, 0, NULL, &c, &v) < 0) {
83: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
84: return 5;
85: }
86: for (i = 0; i < c; i++)
87: printf("registeredCall(%d)=%s\n", i, RPC_GET_STR(&v[i]));
88: rpc_cli_freeVals(c, v);
89: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, 0, NULL, &c, &v) < 0) {
90: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
91: return 6;
92: }
93: printf("c=%d v=%p\n", c, v);
94: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) RPC_GET_U8(&v[0]), (uint32_t) RPC_GET_U32(&v[1]),
95: RPC_GET_U32(&v[2]), RPC_GET_I32(&v[3]));
96: rpc_cli_freeVals(c, v);
97:
1.1.1.1.2.3 misho 98: // rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, 0, NULL, 0, NULL);
1.1.1.1.2.1 misho 99:
1.1.1.1.2.4 misho 100: rpc_cli_closeBLOBClient(cli2);
1.1 misho 101: rpc_cli_closeClient(cli);
102: return 0;
103: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>