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