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