From ff19c9c625642d7ad3bb1f33a758cc7d2842de13 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 21 Aug 2018 10:05:01 +0200 Subject: [PATCH] Added sharedFile::exists() call to match version in sharedPage class, fixed sharedPage::exists not being inside SHM_ENABLED block. --- lib/shared_memory.cpp | 10 +++++++++- lib/shared_memory.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 038bc339..fc2f9548 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -348,6 +348,8 @@ namespace IPC { close(); } +#ifdef SHM_ENABLED + /// Returns true if the open file still exists. /// \TODO Not implemented under Windows. bool sharedPage::exists(){ @@ -364,7 +366,6 @@ namespace IPC { #endif } -#ifdef SHM_ENABLED ///\brief Unmaps a shared page if allowed void sharedPage::unmap() { if (mapped && len) { @@ -561,6 +562,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 f615acdd..0b7f23f2 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -109,9 +109,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