12 #ifndef SST_CORE_INTERPROCESS_TUNNEL_MMAP_PARENT_H 
   13 #define SST_CORE_INTERPROCESS_TUNNEL_MMAP_PARENT_H 
   28 namespace Interprocess {
 
   35 template <
typename TunnelType>
 
   49     MMAPParent(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), 
"/tmp/sst_shmem_%u-%" PRIu32 
"-%d", getpid(), comp_id, rand());
 
   59             fd = open(filename.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
 
   67         } 
while ( (fd < 0) && (errno == EEXIST) );
 
   71             fprintf(stderr, 
"Failed to create IPC region '%s': %s\n", filename.c_str(), strerror(errno));
 
   75         tunnel  = 
new TunnelType(numBuffers, bufferSize, expectedChildren);
 
   76         shmSize = tunnel->getTunnelSize();
 
   78         if ( ftruncate(fd, shmSize) ) {
 
   80             fprintf(stderr, 
"Resizing shared file '%s' failed: %s\n", filename.c_str(), strerror(errno));
 
   84         shmPtr = mmap(
nullptr, shmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 
   85         if ( shmPtr == MAP_FAILED ) {
 
   87             fprintf(stderr, 
"mmap failed: %s\n", strerror(errno));
 
   92         memset(shmPtr, 
'\0', shmSize);
 
   93         tunnel->initialize(shmPtr);
 
  101         munmap(shmPtr, shmSize);
 
  102         if ( 
remove(filename.c_str()) != 0 ) { fprintf(stderr, 
"Error deleting tunnel file: %s\n", filename.c_str()); }
 
  115     std::string filename;
 
  125 #endif // SST_CORE_INTERPROCESS_TUNNEL_MMAP_PARENT_H 
virtual ~MMAPParent()
Destructor. 
Definition: mmapparent.h:97
MMAPParent(uint32_t comp_id, size_t numBuffers, size_t bufferSize, uint32_t expectedChildren=1)
Parent/master manager for an IPC Tunnel Creates a memory-mapped file and initializes a TunnelType dat...
Definition: mmapparent.h:49
TunnelType * getTunnel()
return the created tunnel pointer 
Definition: mmapparent.h:109
const std::string & getRegionName(void) const 
returns name of the mmap'd file 
Definition: mmapparent.h:106
Class supports an IPC tunnel between two or more processes, via an mmap'd file. 
Definition: mmapparent.h:36