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