Annotation of libaitrpc/example/tsrv_un.c, revision 1.1.2.6
1.1.2.1 misho 1: #include <stdio.h>
2: #include <unistd.h>
3: #include <pthread.h>
4: #include <aitrpc.h>
5: #include "rc.h"
6:
7:
8: rpc_srv_t *srv;
9:
10:
11: int aaa(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
12: {
13: // rpc_blob_t *b;
14:
15: RPC_CALLBACK_CHECK_INPUT(cli);
16:
17: printf("%s(%d): Piuk! aaaaaa\n", __func__, __LINE__);
18:
19: /*
20: b = rpc_srv_registerBLOB(f->func_parent, BUFSIZ);
21: if (!b)
22: return -1;
23: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
24: rpc_srv_blobFree(f->func_parent, b);
25: return -1;
26: }
27:
28: memset(b->blob_data, 0, b->blob_len);
29: strcpy(b->blob_data, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa dsfsfsfnskjfnk\n");
30:
31: rpc_srv_blobUnmap(b);
32: */
33:
34: RPC_SET_ERRNO(rpc, EAGAIN);
35: return 0;
36: }
37:
38: int BBB(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
39: {
40: ait_val_t *v;
41: rpc_blob_t *b;
42: rpc_srv_t *s;
43:
44: RPC_CALLBACK_CHECK_INPUT(cli);
45: s = RPC_SRV_SERVER(cli);
46:
47: printf("%s(%d): Piuk! %d %s %X\n", __func__, __LINE__,
48: AIT_GET_I32(array(iv, 0, ait_val_t*)), AIT_GET_STR(array(iv, 1, ait_val_t*)),
49: AIT_GET_BLOB(array(iv, 2, ait_val_t*)));
50:
51: // input blob object
52: if (!(b = rpc_srv_getBLOB(s, AIT_GET_BLOB(array(iv, 2, ait_val_t*)))))
53: return -1;
54: if (rpc_srv_blobMap(s, b) == -1) {
55: rpc_srv_blobFree(s, b);
56: return -1;
57: }
58: printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
59: rpc_srv_blobUnmap(b);
60: rpc_srv_unregisterBLOB(s, AIT_GET_BLOB(array(iv, 2, ait_val_t*)));
61:
62:
63: AIT_SET_BUF(ait_getVars(&RPC_RETVARS(cli), 0), "00!oo", 6);
64: AIT_SET_I8(ait_getVars(&RPC_RETVARS(cli), 1), 65);
65: AIT_SET_STR(ait_getVars(&RPC_RETVARS(cli), 2), "Oho boho i cheburashka");
66:
67: // return blob object
68: b = rpc_srv_registerBLOB(s, 128, 0);
69: if (!b)
70: return -1;
71: else
72: AIT_SET_BLOB2(ait_getVars(&RPC_RETVARS(cli), 3), b);
73:
74: printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
75: memset(b->blob_data, 0, b->blob_len);
76: strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
77:
78: rpc_srv_blobUnmap(b);
79: return 33;
80: }
81:
82: int xxx(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
83: {
84: ait_val_t *v;
85:
86: RPC_CALLBACK_CHECK_INPUT(cli);
87:
88: printf("iv_s=%d\n", array_Size(iv));
89: printf("%s(%d): Piuk! --- %s\n", __func__, __LINE__, AIT_GET_BUF(array(iv, 0, ait_val_t*)));
90:
91: v = ait_getVars(&RPC_RETVARS(cli), 0);
92: AIT_SET_DATA(v, "00!oo", 6);
93: array_Set(RPC_RETVARS(cli), 0, v);
94: AIT_SET_I8(ait_getVars(&RPC_RETVARS(cli), 1), 65);
95: return 111;
96: }
97:
98: int xYz(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
99: {
100: return 0;
101: }
102:
103: int big(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
104: {
105: ait_val_t *v;
106:
107: RPC_CALLBACK_CHECK_INPUT(cli);
108:
109: printf("Ok lets fun... %d\n", array_Size(iv));
110:
1.1.2.3 misho 111: mpool_xdump(">>> %s(%d) ", __func__, __LINE__);
1.1.2.1 misho 112: v = ait_getVars(&RPC_RETVARS(cli), 0);
113: AIT_SET_BUFSIZ(v, '*', AIT_GET_I32(array(iv, 0, ait_val_t*)));
1.1.2.3 misho 114: mpool_xdump(">>> %s(%d) ", __func__, __LINE__);
1.1.2.1 misho 115: return 0;
116: }
117:
118: int main(int argc, char **argv)
119: {
120: rpc_func_t *f;
121: int ret;
122:
123: if (argc > 1) {
124: if (argc > 2)
125: srv = rpc_srv_initServer(2, 3, 1024 * 10, "/tmp/libaitrpc.sock", 0, SOCK_RAW);
126: else
127: srv = rpc_srv_initServer(2, 3, 1024 * 10, "/tmp/libaitrpc.sock", 11111, SOCK_DGRAM);
128: } else
129: srv = rpc_srv_initServer(2, 2, 1024 * 10, "/tmp/libaitrpc.sock", 11111, 0);
130: if (!srv) {
131: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
132: return 1;
133: }
134:
135: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
136: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
137: return 1;
138: }
139:
140: rpc_srv_registerCall(srv, RC_aaa, aaa);
141: rpc_srv_registerCall(srv, RC_BBB, BBB);
142: rpc_srv_registerCall(srv, 3, NULL);
143: rpc_srv_registerCall(srv, RC_xYz, xYz);
144: rpc_srv_registerCall(srv, RC_xxx, xxx);
145: rpc_srv_registerCall(srv, RC_big, big);
146:
147: rpc_srv_unregisterCall(srv, 4);
148:
149: rpc_register_srvServices(srv);
150: rpc_register_blobServices(srv);
151:
1.1.2.3 misho 152: mpool_xdump(NULL);
1.1.2.2 misho 153:
1.1.2.1 misho 154: rpc_srv_execBLOBServer(srv);
155: rpc_srv_loopServer(srv);
156:
157: rpc_srv_endBLOBServer(srv);
158: rpc_srv_endServer(&srv);
1.1.2.3 misho 159: mpool_xdump(NULL);
1.1.2.1 misho 160: return 0;
161: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>