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