Annotation of libaitrpc/example/tsrv.c, revision 1.1.1.1.2.4
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.2 misho 9: RPC_CALLBACK_CHK_NUM_ARGS(f, in);
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.2 misho 33: RPC_CALLBACK_CHK_NUM_ARGS(f, in);
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:
38: rpc_srv_declValsCall(f, 3);
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;
! 47: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
! 48: rpc_srv_blobFree(f->func_parent, b);
! 49: return -1;
! 50: }
! 51:
! 52: printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
! 53: memset(b->blob_data, 0, b->blob_len);
! 54: strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
! 55:
! 56: rpc_srv_blobUnmap(b);
1.1 misho 57: return 33;
58: }
59:
60: int main()
61: {
62: rpc_srv_t *srv;
63: rpc_func_t *f;
1.1.1.1.2.3 misho 64: pthread_t tid[2];
65: int ret;
1.1 misho 66:
67: srv = rpc_srv_initServer(100, 2, 1, 2, "0.0.0.0", 11111);
68: if (!srv) {
69: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
70: return 1;
71: }
72:
1.1.1.1.2.2 misho 73: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
74: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
75: return 1;
76: }
77:
1.1 misho 78: rpc_srv_registerCall(srv, NULL, "aaa", 0);
79: rpc_srv_registerCall(srv, NULL, "BBB", 3);
80: rpc_srv_registerCall(srv, NULL, "dummy", 1);
81: rpc_srv_registerCall(srv, NULL, "xYz", 2);
82:
83: rpc_srv_unregisterCall(srv, NULL, "dummy");
84:
85: for (f = srv->srv_funcs; f; f = f->func_next)
86: printf("func::name=%s args=%d\n", f->func_name, f->func_args);
87:
1.1.1.1.2.1 misho 88: if (!fork()) {
89: setsid();
1.1 misho 90:
1.1.1.1.2.3 misho 91: pthread_create(&tid[1], NULL, rpc_srv_execBLOBServer, srv);
92: rpc_srv_execServer(srv);
1.1 misho 93: }
94:
1.1.1.1.2.2 misho 95: rpc_srv_endBLOBServer(srv);
1.1 misho 96: rpc_srv_endServer(srv);
97: return 0;
98: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>