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