Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2243)

Unified Diff: base/shared_memory.h

Issue 21208: POSIX: Transfer network data using shared memory (Closed)
Patch Set: ... Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_descriptor_posix.h ('k') | base/shared_memory_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/shared_memory.h
diff --git a/base/shared_memory.h b/base/shared_memory.h
index 3bfa003aa203ccd30eb8c45de52d395fc1a9d5a0..b44367a7fcc875e16e91e6e486f73c0316debd15 100644
--- a/base/shared_memory.h
+++ b/base/shared_memory.h
@@ -9,6 +9,7 @@
#if defined(OS_POSIX)
#include <semaphore.h>
+#include "base/file_descriptor_posix.h"
#endif
#include <string>
@@ -23,7 +24,7 @@ namespace base {
typedef HANDLE SharedMemoryHandle;
typedef HANDLE SharedMemoryLock;
#elif defined(OS_POSIX)
-typedef int SharedMemoryHandle;
+typedef FileDescriptor SharedMemoryHandle;
// On POSIX, the lock is implemented as a lockf() on the mapped file,
// so no additional member (or definition of SharedMemoryLock) is
// needed.
@@ -49,6 +50,10 @@ class SharedMemory {
// Destructor. Will close any open files.
~SharedMemory();
+ // Return true iff the given handle is valid (i.e. not the distingished
+ // invalid value; NULL for a HANDLE and -1 for a file descriptor)
+ static bool IsHandleValid(const SharedMemoryHandle& handle);
+
// Creates or opens a shared memory segment based on a name.
// If read_only is true, opens the memory as read-only.
// If open_existing is true, and the shared memory already exists,
@@ -92,7 +97,7 @@ class SharedMemory {
// Get access to the underlying OS handle for this segment.
// Use of this handle for anything other than an opaque
// identifier is not portable.
- SharedMemoryHandle handle() const { return mapped_file_; }
+ SharedMemoryHandle handle() const;
// Closes the open shared memory segment.
// It is safe to call Close repeatedly.
@@ -147,7 +152,11 @@ class SharedMemory {
bool close_self);
std::wstring name_;
- SharedMemoryHandle mapped_file_;
+#if defined(OS_WIN)
+ HANDLE mapped_file_;
+#elif defined(OS_POSIX)
+ int mapped_file_;
+#endif
void* memory_;
bool read_only_;
size_t max_size_;
« no previous file with comments | « base/file_descriptor_posix.h ('k') | base/shared_memory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698