Annotation of libaitrpc/example/tsrv.c, revision 1.3.2.6
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.3.2.3 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:
13: printf("%s(%d): Piuk! %s\n", __func__, __LINE__, 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.3.2.3 misho 32: int BBB(rpc_func_t *f, int in, array_t *iv)
1.1 misho 33: {
1.3.2.1 misho 34: ait_val_t *v;
1.2 misho 35: rpc_blob_t *b;
1.3.2.3 misho 36: array_t *arr;
1.1 misho 37:
1.2 misho 38: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 39:
1.3.2.4 misho 40: // printf("%s(%d): Piuk! %s %d %s %X\n", __func__, __LINE__, f->func_name,
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.2 misho 43: printf("%s(%d): Piuk! %s %d %s %X\n", __func__, __LINE__, f->func_name,
1.3.2.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.3.2.4 misho 47: // if (!(b = rpc_srv_getBLOB(f->func_parent, AIT_GET_BLOB(io_array(iv, 2, ait_val_t*)))))
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);
54: // rpc_srv_unregisterBLOB(f->func_parent, AIT_GET_BLOB(io_array(iv, 2, ait_val_t*)));
1.2 misho 55:
56:
1.3.2.3 misho 57: rpc_srv_getVars(f, &arr);
58: v = io_array(arr, 0, ait_val_t*);
59: AIT_SET_BUF(v, "00!oo", 6);
60: v = io_array(arr, 1, ait_val_t*);
61: AIT_SET_I8(v, 65);
62: v = io_array(arr, 2, ait_val_t*);
63: AIT_SET_STR(v, "Oho boho i cheburashka");
1.2 misho 64:
65: // return blob object
1.3.2.4 misho 66: // b = rpc_srv_registerBLOB(f->func_parent, 128);
67: // if (!b)
68: // return -1;
69: // else
70: // AIT_SET_BLOB2(io_array(arr, 3, ait_val_t*), b);
71:
72: // if (rpc_srv_blobMap(f->func_parent, b) == -1) {
73: // rpc_srv_blobFree(f->func_parent, b);
74: // return -1;
75: // }
76:
77: // printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
78: // memset(b->blob_data, 0, b->blob_len);
79: // strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
1.2 misho 80:
1.3.2.4 misho 81: // rpc_srv_blobUnmap(b);
1.1 misho 82: return 33;
83: }
84:
85: int main()
86: {
87: rpc_srv_t *srv;
88: rpc_func_t *f;
1.2 misho 89: pthread_t tid[2];
90: int ret;
1.1 misho 91:
1.3.2.2 misho 92: srv = rpc_srv_initServer(100, 2, 1, 1024 * 10, AF_INET, "0.0.0.0", 11111);
1.3 misho 93: // srv = rpc_srv_initServer(100, 2, 1, AF_LOCAL, "0.0.0.0", 11111);
1.1 misho 94: if (!srv) {
95: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
96: return 1;
97: }
98:
1.3.2.4 misho 99: /*
1.2 misho 100: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
101: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
102: return 1;
103: }
1.3.2.4 misho 104: */
1.2 misho 105:
106: if (!fork()) {
107: setsid();
108:
109: rpc_srv_registerCall(srv, NULL, "aaa", 0);
1.3.2.6 ! misho 110: rpc_srv_registerCall(srv, NULL, "BBB", 4);
1.2 misho 111: rpc_srv_registerCall(srv, NULL, "dummy", 1);
112: rpc_srv_registerCall(srv, NULL, "xYz", 2);
113:
1.3.2.4 misho 114: /* dump register functions */
115: for (f = srv->srv_funcs; f; f = f->func_next)
116: printf("0.func::name=%s args=%d\n", f->func_name, io_arraySize(f->func_vars));
117:
1.2 misho 118: rpc_srv_unregisterCall(srv, NULL, "dummy");
1.1 misho 119:
1.3.2.4 misho 120: /* dump register functions */
121: for (f = srv->srv_funcs; f; f = f->func_next)
122: printf("1.func::name=%s args=%d\n", f->func_name, io_arraySize(f->func_vars));
123:
124: // pthread_create(&tid[1], NULL, (void*(*)(void*)) rpc_srv_execBLOBServer, srv);
125: // pthread_detach(tid[1]);
1.2 misho 126: rpc_srv_execServer(srv);
1.1 misho 127: }
128:
1.3.2.4 misho 129: // rpc_srv_endBLOBServer(srv);
1.1 misho 130: rpc_srv_endServer(srv);
131: return 0;
132: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>