12#ifndef SST_CORE_INTERPROCESS_TUNNEL_SHM_PARENT_H
13#define SST_CORE_INTERPROCESS_TUNNEL_SHM_PARENT_H
28namespace Interprocess {
35template <
typename TunnelType>
49 SHMParent(uint32_t comp_id,
size_t numBuffers,
size_t bufferSize, uint32_t expectedChildren = 1) :
54 memset(key,
'\0',
sizeof(key));
56 snprintf(key,
sizeof(key),
"/sst_shmem_%u-%" PRIu32
"-%d", getpid(), comp_id, rand());
59 fd = shm_open(filename.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
67 }
while ( (fd < 0) && (errno == EEXIST) );
70 fprintf(stderr,
"Failed to create IPC region '%s': %s\n", filename.c_str(), strerror(errno));
74 tunnel =
new TunnelType(numBuffers, bufferSize, expectedChildren);
75 shmSize = tunnel->getTunnelSize();
77 if ( ftruncate(fd, shmSize) ) {
79 fprintf(stderr,
"Resizing shared file '%s' failed: %s\n", filename.c_str(), strerror(errno));
83 shmPtr = mmap(
nullptr, shmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
84 if ( shmPtr == MAP_FAILED ) {
86 fprintf(stderr,
"mmap failed: %s\n", strerror(errno));
89 memset(shmPtr,
'\0', shmSize);
90 tunnel->initialize(shmPtr);
98 munmap(shmPtr, shmSize);
118 std::string filename;
Class supports an IPC tunnel between two or more processes via posix shared memory This class creates...
Definition: shmparent.h:37
TunnelType * getTunnel()
return the created tunnel pointer
Definition: shmparent.h:112
SHMParent(uint32_t comp_id, size_t numBuffers, size_t bufferSize, uint32_t expectedChildren=1)
Parent/master manager for an IPC tunnel Creates a shared memory region and initializes a TunnelType d...
Definition: shmparent.h:49
virtual ~SHMParent()
Destructor.
Definition: shmparent.h:94
const std::string & getRegionName(void) const
returns name of the mmap'd region
Definition: shmparent.h:109