Annotation of libaitrpc/example/tsrv.c, revision 1.1.1.1.2.7
1.1 misho 1: #include <stdio.h>
2: #include <aitrpc.h>
3:
4:
1.1.1.1.2.2 misho 5: int aaa(rpc_func_t *f, int in, rpc_val_t *iv)
1.1 misho 6: {
1.1.1.1.2.4 misho 7: rpc_blob_t *b;
8:
1.1.1.1.2.7! misho 9: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 10:
11: printf("%s(%d): Piuk! %s\n", __func__, __LINE__, f->func_name);
1.1.1.1.2.4 misho 12:
13: b = rpc_srv_registerBLOB(f->func_parent, BUFSIZ);
14: if (!b)
15: return -1;
16: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
17: rpc_srv_blobFree(f->func_parent, b);
18: return -1;
19: }
20:
21: memset(b->blob_data, 0, b->blob_len);
22: strcpy(b->blob_data, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa dsfsfsfnskjfnk\n");
23:
24: rpc_srv_blobUnmap(b);
1.1 misho 25: return 0;
26: }
27:
1.1.1.1.2.2 misho 28: int BBB(rpc_func_t *f, int in, rpc_val_t *iv)
1.1 misho 29: {
30: rpc_val_t *v;
1.1.1.1.2.4 misho 31: rpc_blob_t *b;
1.1 misho 32:
1.1.1.1.2.7! misho 33: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 34:
1.1.1.1.2.2 misho 35: printf("%s(%d): Piuk! %s %d %s\n", __func__, __LINE__, f->func_name,
36: RPC_GET_I32(&iv[0]), RPC_GET_STR(&iv[1]));
1.1 misho 37:
1.1.1.1.2.5 misho 38: rpc_srv_declValsCall(f, 4);
1.1 misho 39: rpc_srv_getValsCall(f, &v);
40: RPC_SET_BUF(&v[0], "00!oo", 6);
41: RPC_SET_I8(&v[1], 65);
42: RPC_SET_STR(&v[2], "Oho boho i cheburashka");
1.1.1.1.2.4 misho 43:
44: b = rpc_srv_registerBLOB(f->func_parent, 128);
45: if (!b)
46: return -1;
1.1.1.1.2.5 misho 47:
48: RPC_SET_BLOB2(&v[3], b);
49:
1.1.1.1.2.4 misho 50: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
51: rpc_srv_blobFree(f->func_parent, b);
52: return -1;
53: }
54:
55: printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
56: memset(b->blob_data, 0, b->blob_len);
57: strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
58:
59: rpc_srv_blobUnmap(b);
1.1 misho 60: return 33;
61: }
62:
63: int main()
64: {
65: rpc_srv_t *srv;
66: rpc_func_t *f;
1.1.1.1.2.3 misho 67: pthread_t tid[2];
68: int ret;
1.1 misho 69:
70: srv = rpc_srv_initServer(100, 2, 1, 2, "0.0.0.0", 11111);
71: if (!srv) {
72: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
73: return 1;
74: }
75:
1.1.1.1.2.2 misho 76: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
77: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
78: return 1;
79: }
80:
1.1 misho 81: rpc_srv_registerCall(srv, NULL, "aaa", 0);
1.1.1.1.2.6 misho 82: rpc_srv_registerCall(srv, NULL, "BBB", 4);
1.1 misho 83: rpc_srv_registerCall(srv, NULL, "dummy", 1);
84: rpc_srv_registerCall(srv, NULL, "xYz", 2);
85:
86: rpc_srv_unregisterCall(srv, NULL, "dummy");
87:
88: for (f = srv->srv_funcs; f; f = f->func_next)
89: printf("func::name=%s args=%d\n", f->func_name, f->func_args);
90:
1.1.1.1.2.1 misho 91: if (!fork()) {
92: setsid();
1.1 misho 93:
1.1.1.1.2.3 misho 94: pthread_create(&tid[1], NULL, rpc_srv_execBLOBServer, srv);
95: rpc_srv_execServer(srv);
1.1 misho 96: }
97:
1.1.1.1.2.2 misho 98: rpc_srv_endBLOBServer(srv);
1.1 misho 99: rpc_srv_endServer(srv);
100: return 0;
101: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>