Annotation of libaitrpc/example/tsrv_un.c, revision 1.1.2.2
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:
111: v = ait_getVars(&RPC_RETVARS(cli), 0);
112: AIT_SET_BUFSIZ(v, '*', AIT_GET_I32(array(iv, 0, ait_val_t*)));
113: return 0;
114: }
115:
116: int main(int argc, char **argv)
117: {
118: rpc_func_t *f;
119: int ret;
120:
121: if (argc > 1) {
122: if (argc > 2)
123: srv = rpc_srv_initServer(2, 3, 1024 * 10, "/tmp/libaitrpc.sock", 0, SOCK_RAW);
124: else
125: srv = rpc_srv_initServer(2, 3, 1024 * 10, "/tmp/libaitrpc.sock", 11111, SOCK_DGRAM);
126: } else
127: srv = rpc_srv_initServer(2, 2, 1024 * 10, "/tmp/libaitrpc.sock", 11111, 0);
128: if (!srv) {
129: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
130: return 1;
131: }
132:
133: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
134: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
135: return 1;
136: }
137:
138: rpc_srv_registerCall(srv, RC_aaa, aaa);
139: rpc_srv_registerCall(srv, RC_BBB, BBB);
140: rpc_srv_registerCall(srv, 3, NULL);
141: rpc_srv_registerCall(srv, RC_xYz, xYz);
142: rpc_srv_registerCall(srv, RC_xxx, xxx);
143: rpc_srv_registerCall(srv, RC_big, big);
144:
145: rpc_srv_unregisterCall(srv, 4);
146:
147: rpc_register_srvServices(srv);
148: rpc_register_blobServices(srv);
149:
1.1.2.2 ! misho 150: mpool_xdump();
! 151:
1.1.2.1 misho 152: rpc_srv_execBLOBServer(srv);
153: rpc_srv_loopServer(srv);
154:
155: rpc_srv_endBLOBServer(srv);
156: rpc_srv_endServer(&srv);
1.1.2.2 ! misho 157: mpool_xdump();
1.1.2.1 misho 158: return 0;
159: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>