Annotation of libaitrpc/example/tsrv.c, revision 1.12
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.1 misho 32: return 0;
33: }
34:
1.8 misho 35: int BBB(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
1.1 misho 36: {
1.4 misho 37: ait_val_t *v;
1.2 misho 38: rpc_blob_t *b;
1.8 misho 39: rpc_srv_t *s;
1.1 misho 40:
1.8 misho 41: RPC_CALLBACK_CHECK_INPUT(cli);
42: s = RPC_SRV_SERVER(cli);
1.1 misho 43:
1.8 misho 44: printf("%s(%d): Piuk! %d %s %X\n", __func__, __LINE__,
1.10 misho 45: AIT_GET_I32(array(iv, 0, ait_val_t*)), AIT_GET_STR(array(iv, 1, ait_val_t*)),
46: AIT_GET_BLOB(array(iv, 2, ait_val_t*)));
1.1 misho 47:
1.2 misho 48: // input blob object
1.10 misho 49: if (!(b = rpc_srv_getBLOB(s, AIT_GET_BLOB(array(iv, 2, ait_val_t*)))))
1.2 misho 50: return -1;
1.8 misho 51: if (rpc_srv_blobMap(s, b) == -1) {
52: rpc_srv_blobFree(s, b);
1.2 misho 53: return -1;
54: }
55: printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
1.4 misho 56: rpc_srv_blobUnmap(b);
1.10 misho 57: rpc_srv_unregisterBLOB(s, AIT_GET_BLOB(array(iv, 2, ait_val_t*)));
1.2 misho 58:
59:
1.10 misho 60: AIT_SET_BUF(ait_getVars(&RPC_RETVARS(cli), 0), "00!oo", 6);
61: AIT_SET_I8(ait_getVars(&RPC_RETVARS(cli), 1), 65);
62: AIT_SET_STR(ait_getVars(&RPC_RETVARS(cli), 2), "Oho boho i cheburashka");
1.2 misho 63:
64: // return blob object
1.12 ! misho 65: b = rpc_srv_registerBLOB(s, 128, 0);
1.2 misho 66: if (!b)
67: return -1;
1.8 misho 68: else
1.10 misho 69: AIT_SET_BLOB2(ait_getVars(&RPC_RETVARS(cli), 3), b);
1.2 misho 70:
71: printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
72: memset(b->blob_data, 0, b->blob_len);
73: strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
74:
75: rpc_srv_blobUnmap(b);
1.1 misho 76: return 33;
77: }
78:
1.8 misho 79: int xxx(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
1.7 misho 80: {
81: ait_val_t *v;
82:
1.8 misho 83: RPC_CALLBACK_CHECK_INPUT(cli);
1.7 misho 84:
1.10 misho 85: printf("iv_s=%d\n", array_Size(iv));
86: printf("%s(%d): Piuk! --- %s\n", __func__, __LINE__, AIT_GET_BUF(array(iv, 0, ait_val_t*)));
1.7 misho 87:
1.10 misho 88: v = ait_getVars(&RPC_RETVARS(cli), 0);
1.7 misho 89: AIT_SET_DATA(v, "00!oo", 6);
1.10 misho 90: array_Set(RPC_RETVARS(cli), 0, v);
91: AIT_SET_I8(ait_getVars(&RPC_RETVARS(cli), 1), 65);
1.7 misho 92: return 111;
93: }
94:
1.8 misho 95: int xYz(rpc_cli_t *cli, struct tagRPCCall *rpc, array_t *iv)
96: {
97: return 0;
98: }
99:
1.1 misho 100: int main()
101: {
102: rpc_func_t *f;
1.2 misho 103: int ret;
1.1 misho 104:
1.11 misho 105: srv = rpc_srv_initServer(2, 3, 1024 * 10, "0.0.0.0", 11111, SOCK_DGRAM);
106: // srv = rpc_srv_initServer(2, 2, 1024 * 10, "0.0.0.0", 11111, 0);
1.1 misho 107: if (!srv) {
108: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
109: return 1;
110: }
111:
1.2 misho 112: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
113: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
114: return 1;
115: }
1.1 misho 116:
1.8 misho 117: rpc_srv_registerCall(srv, RC_aaa, aaa);
118: rpc_srv_registerCall(srv, RC_BBB, BBB);
119: rpc_srv_registerCall(srv, 3, NULL);
120: rpc_srv_registerCall(srv, RC_xYz, xYz);
121: rpc_srv_registerCall(srv, RC_xxx, xxx);
1.5 misho 122:
1.8 misho 123: rpc_srv_unregisterCall(srv, 4);
1.5 misho 124:
1.8 misho 125: rpc_register_srvServices(srv);
126: rpc_register_blobServices(srv);
1.5 misho 127:
1.8 misho 128: rpc_srv_execBLOBServer(srv);
129: rpc_srv_loopServer(srv);
1.1 misho 130:
1.3 misho 131: rpc_srv_endBLOBServer(srv);
1.5 misho 132: rpc_srv_endServer(&srv);
1.1 misho 133: return 0;
134: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>