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_posix.cc | |
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_posix.cc')
-rw-r--r-- | base/shared_memory_posix.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index bd33cda..e6f81c5 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -29,7 +29,7 @@ SharedMemory::SharedMemory() } SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only) - : mapped_file_(handle), + : mapped_file_(handle.fd), memory_(NULL), read_only_(read_only), max_size_(0) { @@ -37,7 +37,7 @@ SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only) SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only, ProcessHandle process) - : mapped_file_(handle), + : mapped_file_(handle.fd), memory_(NULL), read_only_(read_only), max_size_(0) { @@ -50,6 +50,11 @@ SharedMemory::~SharedMemory() { Close(); } +// static +bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { + return handle.fd >= 0; +} + bool SharedMemory::Create(const std::wstring &name, bool read_only, bool open_existing, size_t size) { read_only_ = read_only; @@ -232,10 +237,15 @@ bool SharedMemory::Unmap() { bool SharedMemory::ShareToProcessCommon(ProcessHandle process, SharedMemoryHandle *new_handle, bool close_self) { - *new_handle = 0; - // TODO(awalker): figure out if we need this, and do the appropriate - // VM magic if so. - return false; + const int new_fd = dup(mapped_file_); + DCHECK(new_fd >= -1); + new_handle->fd = new_fd; + new_handle->auto_close = true; + + if (close_self) + Close(); + + return true; } @@ -277,4 +287,8 @@ void SharedMemory::Unlock() { LockOrUnlockCommon(F_ULOCK); } +SharedMemoryHandle SharedMemory::handle() const { + return FileDescriptor(mapped_file_, false); +} + } // namespace base |