Annotation of libaitrpc/src/blob.c, revision 1.1.2.3
1.1.2.1 misho 1: #include "global.h"
2:
3:
1.1.2.2 misho 4: /*
5: * rpc_srv_blobMap() Map blob to memory region
6: * @srv = RPC Server instance
7: * @blob = Map to this BLOB element
8: * return: -1 error or 0 ok
9: */
10: inline int
11: rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob)
12: {
13: int f;
14: struct stat sb;
15: char szFName[MAXPATHLEN];
16:
17: if (!blob) {
18: rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
19: return -1;
20: }
21:
22: memset(szFName, 0, MAXPATHLEN);
23: snprintf(szFName, MAXPATHLEN, BLOB_FILE, srv->srv_blob.dir, blob->blob_var);
24: f = open(szFName, O_RDONLY);
25: if (f == -1) {
26: LOGERR;
27: return -1;
28: }
29: if (fstat(f, &sb) == -1) {
30: LOGERR;
31: close(f);
32: return -1;
33: }
34:
35: blob->blob_data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, f, 0);
36: if (blob->blob_data == MAP_FAILED) {
37: LOGERR;
38: close(f);
39: blob->blob_data = NULL;
40: return -1;
41: } else {
42: blob->blob_len = sb.st_size;
43: close(f);
44: }
45:
46: return 0;
47: }
48:
49: /*
50: * rpc_srv_blobUnmap() Unmap blob memory region
51: * @blob = Mapped BLOB element
52: * return: none
53: */
54: inline void
55: rpc_srv_blobUnmap(rpc_blob_t * __restrict blob)
56: {
57: if (!blob || !blob->blob_data)
58: rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
59: else {
60: munmap(blob->blob_data, blob->blob_len);
61: blob->blob_data = NULL;
62: blob->blob_len = 0;
63: }
64: }
65:
66: /*
67: * rpc_srv_blobFree() Free blob from disk & memory
68: * @srv = RPC Server instance
69: * @blob = Mapped BLOB element
70: * return: -1 error or 0 ok
71: */
72: inline int
73: rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob)
74: {
75: char szFName[MAXPATHLEN];
76:
77: if (!blob) {
78: rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
79: return -1;
80: }
81:
82: if (blob->blob_data)
83: rpc_srv_blobUnmap(blob);
84:
85: memset(szFName, 0, MAXPATHLEN);
86: snprintf(szFName, MAXPATHLEN, BLOB_FILE, srv->srv_blob.dir, blob->blob_var);
87: if (remove(szFName) == -1) {
88: LOGERR;
89: return -1;
90: }
91:
92: return 0;
93: }
94:
95: // ------------------------------------------------------------
96:
1.1.2.3 ! misho 97: /*
! 98: * rpc_srv_sendBLOB() Send mapped BLOB to client
! 99: * @cli = Client instance
! 100: * @blob = Mapped BLOB element
! 101: * return: -1 error, 0 ok
! 102: */
1.1.2.2 misho 103: int
1.1.2.3 ! misho 104: rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob)
1.1.2.2 misho 105: {
1.1.2.3 ! misho 106: int ret, len;
! 107: uint8_t *pos;
1.1.2.2 misho 108:
1.1.2.3 ! misho 109: if (!cli || !blob || !blob->blob_data) {
1.1.2.2 misho 110: rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
111: return -1;
112: }
113:
1.1.2.3 ! misho 114: for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len)
! 115: if ((len = send(cli->cli_sock, pos, ret > BLOBSIZ ? BLOBSIZ : ret, 0)) == -1) {
! 116: LOGERR;
! 117: return -1;
! 118: }
1.1.2.2 misho 119:
1.1.2.3 ! misho 120: return ret;
! 121: }
! 122:
! 123: /*
! 124: * rpc_srv_recvBLOB() Receive BLOB from client
! 125: * @cli = Client instance
! 126: * return: -1 error, 0 ok
! 127: */
! 128: int
! 129: rpc_srv_recvBLOB(rpc_cli_t * __restrict cli)
! 130: {
! 131: int ret, len;
! 132: uint8_t *pos;
! 133: rpc_srv_t *s;
! 134:
! 135: if (!cli || !cli->cli_parent) {
! 136: rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
! 137: return -1;
! 138: } else
! 139: s = cli->cli_parent;
! 140:
! 141:
! 142: return ret;
1.1.2.2 misho 143: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>