diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 18:59:20 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 18:59:20 +0000 |
commit | 5fe733dee6afd3ab897cafbfcdcc1450264409b0 (patch) | |
tree | 64d39f452e1aee1076356da52d836c902e8b92eb /base/shared_memory.h | |
parent | 072f6f57560ab3616915b0aa9f61331deb2cf260 (diff) | |
download | chromium_src-5fe733dee6afd3ab897cafbfcdcc1450264409b0.zip chromium_src-5fe733dee6afd3ab897cafbfcdcc1450264409b0.tar.gz chromium_src-5fe733dee6afd3ab897cafbfcdcc1450264409b0.tar.bz2 |
POSIX: Transfer network data using shared memory
This patch adds the long planned support for sharing memory on POSIX
by transporting file descriptors. It largely builds on the shared
memory cleanup work by jrg.
We move FileDescriptor out of chrome/common/file_descriptor_posix.h
and into base/file_descriptor_posix.h. Since all that's left in the
chrome/common verion is the DescriptorSet, those files are renamed to
descriptor_set.[h|cc].
The SharedMemoryHandle on POSIX then becomes a typedef to a
FileDescriptor and thus can be serialised over IPC.
After that, it's mostly a case of cleaning up those snippets of code
which considered SharedMemoryHandles to be scaler values.
Review URL: http://codereview.chromium.org/21208
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory.h')
-rw-r--r-- | base/shared_memory.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h index 3bfa003..b44367a 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_; |