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