Annotation of libaitrpc/example/tsrv.c, revision 1.15
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: {
104: RPC_CALLBACK_CHECK_INPUT(cli);
105: ait_val_t *v;
106:
107: printf("Ok lets fun... %d\n", array_Size(iv));
108:
109: v = ait_getVars(&RPC_RETVARS(cli), 0);
110: AIT_SET_BUFSIZ(v, '*', 500000);
111: return 0;
112: }
113:
1.13 misho 114: int main(int argc, char **argv)
1.1 misho 115: {
116: rpc_func_t *f;
1.2 misho 117: int ret;
1.1 misho 118:
1.13 misho 119: if (argc > 1)
120: srv = rpc_srv_initServer(2, 3, 1024 * 10, "0.0.0.0", 11111, SOCK_DGRAM);
121: else
122: srv = rpc_srv_initServer(2, 2, 1024 * 10, "0.0.0.0", 11111, 0);
1.1 misho 123: if (!srv) {
124: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
125: return 1;
126: }
127:
1.2 misho 128: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
129: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
130: return 1;
131: }
1.1 misho 132:
1.8 misho 133: rpc_srv_registerCall(srv, RC_aaa, aaa);
134: rpc_srv_registerCall(srv, RC_BBB, BBB);
135: rpc_srv_registerCall(srv, 3, NULL);
136: rpc_srv_registerCall(srv, RC_xYz, xYz);
137: rpc_srv_registerCall(srv, RC_xxx, xxx);
1.14 misho 138: rpc_srv_registerCall(srv, RC_big, big);
1.5 misho 139:
1.8 misho 140: rpc_srv_unregisterCall(srv, 4);
1.5 misho 141:
1.8 misho 142: rpc_register_srvServices(srv);
143: rpc_register_blobServices(srv);
1.5 misho 144:
1.8 misho 145: rpc_srv_execBLOBServer(srv);
146: rpc_srv_loopServer(srv);
1.1 misho 147:
1.3 misho 148: rpc_srv_endBLOBServer(srv);
1.5 misho 149: rpc_srv_endServer(&srv);
1.1 misho 150: return 0;
151: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>