Annotation of libaitrpc/example/tsrv.c, revision 1.2.4.5
1.1 misho 1: #include <stdio.h>
1.2 misho 2: #include <pthread.h>
1.1 misho 3: #include <aitrpc.h>
4:
5:
1.2.4.5 ! misho 6: #define sTYPE SOCK_STREAM
! 7:
! 8:
1.2 misho 9: int aaa(rpc_func_t *f, int in, rpc_val_t *iv)
1.1 misho 10: {
1.2 misho 11: rpc_blob_t *b;
12:
13: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 14:
15: printf("%s(%d): Piuk! %s\n", __func__, __LINE__, f->func_name);
1.2 misho 16:
17: /*
18: b = rpc_srv_registerBLOB(f->func_parent, BUFSIZ);
19: if (!b)
20: return -1;
21: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
22: rpc_srv_blobFree(f->func_parent, b);
23: return -1;
24: }
25:
26: memset(b->blob_data, 0, b->blob_len);
27: strcpy(b->blob_data, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa dsfsfsfnskjfnk\n");
28:
29: rpc_srv_blobUnmap(b);
30: */
1.1 misho 31: return 0;
32: }
33:
1.2 misho 34: int BBB(rpc_func_t *f, int in, rpc_val_t *iv)
1.1 misho 35: {
36: rpc_val_t *v;
1.2 misho 37: rpc_blob_t *b;
1.1 misho 38:
1.2 misho 39: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 40:
1.2 misho 41: printf("%s(%d): Piuk! %s %d %s %X\n", __func__, __LINE__, f->func_name,
42: RPC_GET_I32(&iv[0]), RPC_GET_STR(&iv[1]), RPC_GET_BLOB(&iv[2]));
1.1 misho 43:
1.2 misho 44: // input blob object
45: if (!(b = rpc_srv_getBLOB(f->func_parent, RPC_GET_BLOB(&iv[2]))))
46: return -1;
47: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
48: rpc_srv_blobFree(f->func_parent, b);
49: return -1;
50: }
51: printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
52: rpc_srv_unregisterBLOB(f->func_parent, RPC_GET_BLOB(&iv[2]));
53:
54:
1.2.4.4 misho 55: rpc_srv_allocVars(f, 4);
56: rpc_srv_getVars(f, &v);
1.1 misho 57: RPC_SET_BUF(&v[0], "00!oo", 6);
58: RPC_SET_I8(&v[1], 65);
59: RPC_SET_STR(&v[2], "Oho boho i cheburashka");
1.2 misho 60:
61: // return blob object
62: b = rpc_srv_registerBLOB(f->func_parent, 128);
63: if (!b)
64: return -1;
65: else
66: RPC_SET_BLOB2(&v[3], b);
67:
68: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
69: rpc_srv_blobFree(f->func_parent, b);
70: return -1;
71: }
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:
81: int main()
82: {
83: rpc_srv_t *srv;
84: rpc_func_t *f;
1.2 misho 85: pthread_t tid[2];
86: int ret;
1.1 misho 87:
1.2.4.5 ! misho 88: srv = rpc_srv_initServer(100, 2, 1, sTYPE, AF_INET, "0.0.0.0", 11111);
1.1 misho 89: if (!srv) {
90: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
91: return 1;
92: }
93:
1.2.4.5 ! misho 94: if (rpc_srv_initBLOBServer(srv, sTYPE, 0, "/tmp")) {
1.2 misho 95: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
96: return 1;
97: }
1.1 misho 98:
1.2 misho 99: /* dump register functions
1.1 misho 100: for (f = srv->srv_funcs; f; f = f->func_next)
101: printf("func::name=%s args=%d\n", f->func_name, f->func_args);
1.2 misho 102: */
103:
104: if (!fork()) {
105: setsid();
106:
107: rpc_srv_registerCall(srv, NULL, "aaa", 0);
108: rpc_srv_registerCall(srv, NULL, "BBB", 4);
109: rpc_srv_registerCall(srv, NULL, "dummy", 1);
110: rpc_srv_registerCall(srv, NULL, "xYz", 2);
111:
112: rpc_srv_unregisterCall(srv, NULL, "dummy");
1.1 misho 113:
1.2 misho 114: pthread_create(&tid[1], NULL, (void*(*)(void*)) rpc_srv_execBLOBServer, srv);
115: rpc_srv_execServer(srv);
1.1 misho 116: }
117:
1.2.4.3 misho 118: rpc_srv_endBLOBServer(srv);
1.1 misho 119: rpc_srv_endServer(srv);
120: return 0;
121: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>