Annotation of libaitrpc/example/tcli.c, revision 1.1.1.1.2.12
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.10 misho 36: /* test case for unknown blob ...
1.1.1.1.2.6 misho 37: RPC_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
1.1.1.1.2.10 misho 38: printf("test not found blob=%d\n", rpc_cli_getBLOB(cli2, &tval, (void**) &mem));
1.1.1.1.2.6 misho 39: if (mem)
40: free(mem);
1.1.1.1.2.10 misho 41: */
1.1.1.1.2.6 misho 42:
1.1 misho 43: // for (i = 0; i < 1000000; i++)
44: if ((ret = rpc_cli_execCall(cli, NULL, "BBB", 3, valz, &c, &v)) < 0) {
45: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
46: return 2;
47: } else {
48: printf("ret=%d\n", ret);
1.1.1.1.2.2 misho 49: if (c && v) {
50: printf("ret_val0:: %p %s len=%d type=%d\n",
51: &v[0], RPC_GET_BUF(&v[0]), RPC_LEN_VAL(&v[0]), RPC_TYPE_VAL(&v[0]));
52: printf("ret_val1:: %d len=%d type=%d\n",
53: RPC_GET_I8(&v[1]), RPC_LEN_VAL(&v[1]), RPC_TYPE_VAL(&v[1]));
54: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
55: 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.10 misho 56: printf("ret_val3:: %X %d\n", RPC_GET_BLOB(&v[3]), RPC_LEN_VAL(&v[3]));
57: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, &v[3], (void**) &mem));
1.1.1.1.2.6 misho 58: if (mem) {
59: printf("BLOB=%s", mem);
60: free(mem);
61: }
1.1.1.1.2.2 misho 62: RPC_FREE_VAL(&v[0]);
63: RPC_FREE_VAL(&v[1]);
64: RPC_FREE_VAL(&v[2]);
1.1.1.1.2.6 misho 65: RPC_FREE_VAL(&v[3]);
1.1.1.1.2.2 misho 66: rpc_cli_freeVals(c, v);
67: }
1.1 misho 68: }
69: RPC_FREE_VAL(&valz[0]);
70: RPC_FREE_VAL(&valz[1]);
71: RPC_FREE_VAL(&valz[2]);
1.1.1.1.2.3 misho 72: free(blob43);
1.1 misho 73:
74: if (rpc_cli_execCall(cli, NULL, "aaa", 0, NULL, &c, &v) < 0) {
75: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
76: return 3;
77: }
78:
79: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, 0, NULL, &c, &v) < 0) {
80: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
81: return 4;
82: }
1.1.1.1.2.3 misho 83: printf("return=%d registeredClient\n", c);
1.1 misho 84: for (i = 0; i < c; i++)
1.1.1.1.2.3 misho 85: printf("registeredClient(%d)=%s\n", i, RPC_GET_STR(&v[i]));
1.1 misho 86: rpc_cli_freeVals(c, v);
1.1.1.1.2.3 misho 87: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, 0, NULL, &c, &v) < 0) {
88: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
89: return 4;
90: }
91: printf("return=%d registeredBLOBClient\n", c);
92: for (i = 0; i < c; i++)
93: printf("registeredBLOBClient(%d)=%s\n", i, RPC_GET_STR(&*v));
94: rpc_cli_freeVals(c, v);
95:
1.1.1.1.2.6 misho 96: if (rpc_cli_execCall(cli, NULL, CALL_BLOBVARS, 0, NULL, &c, &v) < 0) {
97: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
98: return 5;
99: }
100: for (i = 0; i < c; i++)
101: printf("registeredBLOBVars(%d)=%0X\n", i, RPC_GET_U32(&v[i]));
102: rpc_cli_freeVals(c, v);
1.1 misho 103: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, 0, NULL, &c, &v) < 0) {
104: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
105: return 5;
106: }
107: for (i = 0; i < c; i++)
108: printf("registeredCall(%d)=%s\n", i, RPC_GET_STR(&v[i]));
109: rpc_cli_freeVals(c, v);
110: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, 0, NULL, &c, &v) < 0) {
111: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
112: return 6;
113: }
114: printf("c=%d v=%p\n", c, v);
115: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) RPC_GET_U8(&v[0]), (uint32_t) RPC_GET_U32(&v[1]),
116: RPC_GET_U32(&v[2]), RPC_GET_I32(&v[3]));
117: rpc_cli_freeVals(c, v);
118:
1.1.1.1.2.12! misho 119: rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, 0, NULL, 0, NULL);
1.1.1.1.2.1 misho 120:
1.1.1.1.2.4 misho 121: rpc_cli_closeBLOBClient(cli2);
1.1 misho 122: rpc_cli_closeClient(cli);
123: return 0;
124: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>