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