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