diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 3eda92ea..0b32f20c 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -349,6 +349,8 @@ namespace IPC { close(); } +#ifdef SHM_ENABLED + /// Returns true if the open file still exists. /// \TODO Not implemented under Windows. bool sharedPage::exists(){ @@ -365,7 +367,6 @@ namespace IPC { #endif } -#ifdef SHM_ENABLED ///\brief Unmaps a shared page if allowed void sharedPage::unmap() { if (mapped && len) { @@ -562,6 +563,13 @@ namespace IPC { } } + /// Returns true if the open file still exists. + bool sharedFile::exists(){ + struct stat sb; + if (fstat(handle, &sb)){return false;} + return (sb.st_nlink > 0); + } + ///\brief Initialize a page, de-initialize before if needed ///\param name_ The name of the page to be created ///\param len_ The size to make the page diff --git a/lib/shared_memory.h b/lib/shared_memory.h index 43d0d3a6..2e202b0e 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -110,9 +110,9 @@ namespace IPC { bool operator < (const sharedFile & rhs) const { return name < rhs.name; } - bool exists(){return true;} void close(); void unmap(); + bool exists(); ///\brief The fd handle of the opened shared file int handle; ///\brief The name of the opened shared file