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

Unified Diff: base/shared_memory_posix.cc

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/shared_memory.h ('k') | base/shared_memory_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/shared_memory_posix.cc
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
index bd33cda006d6ec08557cf2ebb8d32208e6ef86e8..e6f81c52961ce4a199fd323cf12b47fe61cd8018 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
« no previous file with comments | « base/shared_memory.h ('k') | base/shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698