Annotation of libaitrpc/example/tsrv.c, revision 1.3.2.1
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.1 ! misho 7: int aaa(rpc_func_t *f, int in, ait_val_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.1 ! misho 32: int BBB(rpc_func_t *f, int in, ait_val_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.1 misho 36:
1.2 misho 37: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 38:
1.2 misho 39: printf("%s(%d): Piuk! %s %d %s %X\n", __func__, __LINE__, f->func_name,
1.3.2.1 ! misho 40: AIT_GET_I32(&iv[0]), AIT_GET_STR(&iv[1]), AIT_GET_BLOB(&iv[2]));
1.1 misho 41:
1.2 misho 42: // input blob object
1.3.2.1 ! misho 43: if (!(b = rpc_srv_getBLOB(f->func_parent, AIT_GET_BLOB(&iv[2]))))
1.2 misho 44: return -1;
45: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
46: rpc_srv_blobFree(f->func_parent, b);
47: return -1;
48: }
49: printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
1.3.2.1 ! misho 50: rpc_srv_unregisterBLOB(f->func_parent, AIT_GET_BLOB(&iv[2]));
1.2 misho 51:
52:
1.3 misho 53: rpc_srv_allocVars(f, 4);
54: rpc_srv_getVars(f, &v);
1.3.2.1 ! misho 55: AIT_SET_BUF(&v[0], "00!oo", 6);
! 56: AIT_SET_I8(&v[1], 65);
! 57: AIT_SET_STR(&v[2], "Oho boho i cheburashka");
1.2 misho 58:
59: // return blob object
60: b = rpc_srv_registerBLOB(f->func_parent, 128);
61: if (!b)
62: return -1;
63: else
1.3.2.1 ! misho 64: AIT_SET_BLOB2(&v[3], b);
1.2 misho 65:
66: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
67: rpc_srv_blobFree(f->func_parent, b);
68: return -1;
69: }
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:
79: int main()
80: {
81: rpc_srv_t *srv;
82: rpc_func_t *f;
1.2 misho 83: pthread_t tid[2];
84: int ret;
1.1 misho 85:
1.3 misho 86: srv = rpc_srv_initServer(100, 2, 1, AF_INET, "0.0.0.0", 11111);
87: // srv = rpc_srv_initServer(100, 2, 1, AF_LOCAL, "0.0.0.0", 11111);
1.1 misho 88: if (!srv) {
89: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
90: return 1;
91: }
92:
1.2 misho 93: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
94: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
95: return 1;
96: }
1.1 misho 97:
1.2 misho 98: /* dump register functions
1.1 misho 99: for (f = srv->srv_funcs; f; f = f->func_next)
100: printf("func::name=%s args=%d\n", f->func_name, f->func_args);
1.2 misho 101: */
102:
103: if (!fork()) {
104: setsid();
105:
106: rpc_srv_registerCall(srv, NULL, "aaa", 0);
107: rpc_srv_registerCall(srv, NULL, "BBB", 4);
108: rpc_srv_registerCall(srv, NULL, "dummy", 1);
109: rpc_srv_registerCall(srv, NULL, "xYz", 2);
110:
111: rpc_srv_unregisterCall(srv, NULL, "dummy");
1.1 misho 112:
1.2 misho 113: pthread_create(&tid[1], NULL, (void*(*)(void*)) rpc_srv_execBLOBServer, srv);
114: rpc_srv_execServer(srv);
1.1 misho 115: }
116:
1.3 misho 117: rpc_srv_endBLOBServer(srv);
1.1 misho 118: rpc_srv_endServer(srv);
119: return 0;
120: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>