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