26 constexpr auto const OMODE_CREATE = O_EXCL | O_CREAT | O_RDWR | O_CLOEXEC;
27 constexpr auto const OMODE_RO = O_RDONLY | O_CLOEXEC;
28 constexpr auto const OMODE_RW = O_RDWR | O_CLOEXEC;
34 if (
auto error = ::posix_fallocate(
_fd, 0, payloadSize); error != 0)
36#elif defined __APPLE__
37 if (::ftruncate(
_fd, payloadSize) < 0)
39 auto const error = errno;
43 throw std::system_error(error, std::generic_category(),
"Could not resize shared memory segment.");
81 if (
struct stat statBuf; ::fstat(
_fd, &statBuf) != -1)
83 if (
static_cast<std::size_t
>(statBuf.st_size) >= payloadSize)
85 auto const shared_data_buffer = ::mmap(
86 nullptr, statBuf.st_size, PROT_READ | ((mode !=
AccessMode::READ_ONLY) ? PROT_WRITE : 0), MAP_FILE | MAP_SHARED,
_fd, 0);
87 if (shared_data_buffer != MAP_FAILED)
89 _data = shared_data_buffer;
94 throw std::system_error(errno, std::generic_category(),
"Could not map shared memory segment.");
99 throw std::system_error(ENOMEM, std::generic_category(),
"Shared memory segment does not meet the minimum size requirements.");