Annotation of libaitrpc/example/tcli.c, revision 1.2.4.3
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]));
60: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, &v[3], (void**) &mem));
61: if (mem) {
62: printf("BLOB=%s", mem);
63: free(mem);
64: }
65: RPC_FREE_VAL(&v[0]);
66: RPC_FREE_VAL(&v[1]);
67: RPC_FREE_VAL(&v[2]);
68: RPC_FREE_VAL(&v[3]);
69: rpc_cli_freeVals(c, v);
70: }
1.1 misho 71: }
72: RPC_FREE_VAL(&valz[0]);
73: RPC_FREE_VAL(&valz[1]);
74: RPC_FREE_VAL(&valz[2]);
1.2 misho 75: free(blob43);
1.1 misho 76:
77: if (rpc_cli_execCall(cli, NULL, "aaa", 0, NULL, &c, &v) < 0) {
78: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
79: return 3;
80: }
81:
82: if (rpc_cli_execCall(cli, NULL, CALL_SRVCLIENTS, 0, NULL, &c, &v) < 0) {
83: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
84: return 4;
85: }
1.2 misho 86: printf("return=%d registeredClient\n", c);
1.1 misho 87: for (i = 0; i < c; i++)
1.2 misho 88: printf("registeredClient(%d)=%s\n", i, RPC_GET_STR(&v[i]));
89: rpc_cli_freeVals(c, v);
90: if (rpc_cli_execCall(cli, NULL, CALL_BLOBCLIENTS, 0, NULL, &c, &v) < 0) {
91: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
92: return 4;
93: }
94: printf("return=%d registeredBLOBClient\n", c);
95: for (i = 0; i < c; i++)
96: printf("registeredBLOBClient(%d)=%s\n", i, RPC_GET_STR(&*v));
97: rpc_cli_freeVals(c, v);
98:
99: if (rpc_cli_execCall(cli, NULL, CALL_BLOBVARS, 0, NULL, &c, &v) < 0) {
100: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
101: return 5;
102: }
103: for (i = 0; i < c; i++)
104: printf("registeredBLOBVars(%d)=%0X\n", i, RPC_GET_U32(&v[i]));
1.1 misho 105: rpc_cli_freeVals(c, v);
106: if (rpc_cli_execCall(cli, NULL, CALL_SRVCALLS, 0, NULL, &c, &v) < 0) {
107: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
108: return 5;
109: }
110: for (i = 0; i < c; i++)
111: printf("registeredCall(%d)=%s\n", i, RPC_GET_STR(&v[i]));
112: rpc_cli_freeVals(c, v);
113: if (rpc_cli_execCall(cli, NULL, CALL_SRVSESSIONS, 0, NULL, &c, &v) < 0) {
114: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
115: return 6;
116: }
117: printf("c=%d v=%p\n", c, v);
118: printf("session(%d:%d:%d) clients=%d\n", (uint8_t) RPC_GET_U8(&v[0]), (uint32_t) RPC_GET_U32(&v[1]),
119: RPC_GET_U32(&v[2]), RPC_GET_I32(&v[3]));
120: rpc_cli_freeVals(c, v);
121:
1.2 misho 122: rpc_cli_execCall(cli, NULL, CALL_SRVSHUTDOWN, 0, NULL, 0, NULL);
123:
124: rpc_cli_closeBLOBClient(cli2);
1.1 misho 125: rpc_cli_closeClient(cli);
126: return 0;
127: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>