From bea8678df95e9496f26074e570e0e2ec339f44e3 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 9 Feb 2018 13:44:53 +0100 Subject: [PATCH] Added sharedPage::exists() call --- lib/shared_memory.cpp | 12 ++++++++++++ lib/shared_memory.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index cb8e81c6..bcb3405e 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -348,6 +348,18 @@ namespace IPC { close(); } + /// Returns true if the open file still exists. + /// Not implemented under Windows. + bool sharedPage::exists(){ +#ifdef SHM_ENABLED + struct stat sb; + if (fstat(handle, &sb)){return false;} + return (sb.st_nlink > 0); +#else + return true; +#endif + } + #ifdef SHM_ENABLED ///\brief Unmaps a shared page if allowed void sharedPage::unmap() { diff --git a/lib/shared_memory.h b/lib/shared_memory.h index 5e329e68..f615acdd 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -109,6 +109,7 @@ namespace IPC { bool operator < (const sharedFile & rhs) const { return name < rhs.name; } + bool exists(){return true;} void close(); void unmap(); ///\brief The fd handle of the opened shared file @@ -143,6 +144,7 @@ namespace IPC { } void unmap(); void close(); + bool exists(); #if defined(__CYGWIN__) || defined(_WIN32) ///\brief The handle of the opened shared memory page HANDLE handle;