|
static bool | unlink (const std::string &path) |
|
Definition at line 19 of file SharedMemory.h.
◆ SharedMemory() [1/3]
Definition at line 24 of file SharedMemory.cc.
25 : m_fd(-1), m_path(), m_size(0), m_addr(NULL) {}
◆ SharedMemory() [2/3]
Definition at line 27 of file SharedMemory.cc.
28 : m_fd(-1), m_path(path), m_size(size), m_addr(NULL)
29{
30}
◆ SharedMemory() [3/3]
Definition at line 32 of file SharedMemory.cc.
33 : m_fd(file.m_fd), m_path(file.m_path),
34 m_size(file.m_size), m_addr(file.m_addr) {}
◆ ~SharedMemory()
◆ close()
Definition at line 64 of file SharedMemory.cc.
65{
66 if (m_fd > 0) {
67 if (m_addr != NULL) munmap(m_addr, m_size);
68 ::close(m_fd);
69 m_fd = 0;
70 }
71}
◆ getfd()
◆ getPath()
const std::string & getPath |
( |
| ) |
const |
|
inline |
◆ isOpened()
◆ map() [1/2]
Definition at line 102 of file SharedMemory.cc.
103{
104 if (m_addr == NULL) m_addr = map(0, m_size);
105 return m_addr;
106}
◆ map() [2/2]
void * map |
( |
size_t |
offset, |
|
|
size_t |
size |
|
) |
| |
Definition at line 88 of file SharedMemory.cc.
89{
90 errno = 0;
91 void* addr = ::mmap(NULL, size, PROT_READ | PROT_WRITE,
92 MAP_SHARED, m_fd, offset);
93 if (addr == MAP_FAILED) {
94 perror("mmap");
95 addr = NULL;
96 }
97 m_addr = addr;
98 m_size = size;
99 return addr;
100}
◆ open() [1/2]
Definition at line 59 of file SharedMemory.cc.
60{
61 return open(m_path, m_size);
62}
◆ open() [2/2]
bool open |
( |
const std::string & |
path, |
|
|
size_t |
size |
|
) |
| |
Definition at line 38 of file SharedMemory.cc.
39{
40 errno = 0;
41 int fd = ::shm_open(path.c_str(), O_CREAT | O_EXCL | O_RDWR, 0666);
42 if (fd < 0) {
43 if (errno != EEXIST) {
44 perror("shm_oepn");
45 return false;
46 }
47 fd = ::shm_open(path.c_str(), O_CREAT | O_RDWR, 0666);
48 if (fd < 0) {
49 perror("shm_oepn");
50 return false;
51 }
52 }
53 m_fd = fd;
54 m_path = path;
55 truncate(size);
56 return true;
57}
◆ operator=()
Definition at line 129 of file SharedMemory.cc.
130{
131 m_fd = file.m_fd;
132 m_path = file.m_path;
133 m_size = file.m_size;
134 m_addr = file.m_addr;
135 return *this;
136}
◆ seekBy()
bool seekBy |
( |
size_t |
offset | ) |
|
Definition at line 119 of file SharedMemory.cc.
120{
121 return (lseek(m_fd, offset, SEEK_CUR) == -1);
122}
◆ seekTo()
bool seekTo |
( |
size_t |
offset | ) |
|
Definition at line 114 of file SharedMemory.cc.
115{
116 return (lseek(m_fd, offset, SEEK_SET) == -1);
117}
◆ size()
◆ truncate()
bool truncate |
( |
size_t |
size | ) |
|
Definition at line 73 of file SharedMemory.cc.
74{
75 if (size > 0) {
76 ::ftruncate(m_fd, size);
77 m_size = size;
78 return true;
79 } else {
80 struct stat st;
81 fstat(m_fd, &st);
82 m_size = st.st_size;
83 }
84 return false;
85}
◆ unlink() [1/2]
Definition at line 108 of file SharedMemory.cc.
109{
110 close();
111 return (unlink(m_path));
112}
◆ unlink() [2/2]
bool unlink |
( |
const std::string & |
path | ) |
|
|
static |
Definition at line 19 of file SharedMemory.cc.
20{
21 return (::shm_unlink(path.c_str()) == -1);
22}
◆ m_addr
◆ m_fd
◆ m_path
◆ m_size
The documentation for this class was generated from the following files: