WvStreams
utils
wvshmzone.cc
1
/*
2
* Worldvisions Weaver Software:
3
* Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4
*
5
* A shared-memory zone via mmap(). See wvshmzone.h.
6
*/
7
#include "wvshmzone.h"
8
#include <sys/mman.h>
9
#include <sys/types.h>
10
#include <sys/stat.h>
11
#include <fcntl.h>
12
#include <assert.h>
13
#include <errno.h>
14
#include <unistd.h>
15
16
WvShmZone::WvShmZone
(
size_t
_size)
17
{
18
size = (int)_size;
19
assert(size > 0);
20
21
buf = NULL;
22
23
fd = open(
"/dev/zero"
, O_RDWR);
24
if
(fd < 0)
25
{
26
seterr
(errno);
27
return
;
28
}
29
30
buf = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
31
32
if
(!buf)
33
{
34
seterr
(errno);
35
return
;
36
}
37
}
38
39
40
WvShmZone::~WvShmZone()
41
{
42
if
(buf)
43
munmap(buf, size);
44
if
(fd >= 0)
45
close(fd);
46
}
47
48
WvErrorBase::seterr
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
Definition:
wverror.cc:144
WvShmZone::WvShmZone
WvShmZone(size_t size)
Creates a shared memory zone.
Definition:
wvshmzone.cc:16
Generated by
1.8.17