summaryrefslogtreecommitdiffstats
path: root/ipc/file_descriptor_set_posix.h
diff options
context:
space:
mode:
authormorrita <morrita@chromium.org>2014-09-24 13:11:45 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-24 20:11:59 +0000
commit96693856edc35a538f6ea8f0bd6ab55c75e3e823 (patch)
tree33bf28816211d8c3a5039db1d2f3a1ac74adf59e /ipc/file_descriptor_set_posix.h
parent33169d9f2497a79fdde3ae51c5aa7266032526c7 (diff)
downloadchromium_src-96693856edc35a538f6ea8f0bd6ab55c75e3e823.zip
chromium_src-96693856edc35a538f6ea8f0bd6ab55c75e3e823.tar.gz
chromium_src-96693856edc35a538f6ea8f0bd6ab55c75e3e823.tar.bz2
IPC: Get rid of FileDescriptor usage from FileDescriptorSet and Message
This is a step toward to killing FileDescriptor. This change lets FiileDescriptorSet have both Files (for owning fds) and PlatformFiles (for non-owning fds). Doing this, we no longer need FileDescriptor which provides |auto_close| flag. BUG=415294 TEST=ipc_tests, ipc_mojo_unittests R=agl@chromium.org, jam@hcromium.org, viettrungluu@chromium.org Review URL: https://codereview.chromium.org/583473002 Cr-Commit-Position: refs/heads/master@{#296498}
Diffstat (limited to 'ipc/file_descriptor_set_posix.h')
-rw-r--r--ipc/file_descriptor_set_posix.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/ipc/file_descriptor_set_posix.h b/ipc/file_descriptor_set_posix.h
index b413b4a..d454962 100644
--- a/ipc/file_descriptor_set_posix.h
+++ b/ipc/file_descriptor_set_posix.h
@@ -8,8 +8,9 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/file_descriptor_posix.h"
+#include "base/files/file.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_vector.h"
#include "ipc/ipc_export.h"
// -----------------------------------------------------------------------------
@@ -36,10 +37,10 @@ class IPC_EXPORT FileDescriptorSet
// Interfaces for building during message serialisation...
// Add a descriptor to the end of the set. Returns false iff the set is full.
- bool Add(int fd);
+ bool AddToBorrow(base::PlatformFile fd);
// Add a descriptor to the end of the set and automatically close it after
// transmission. Returns false iff the set is full.
- bool AddAndAutoClose(int fd);
+ bool AddToOwn(base::ScopedFD fd);
// ---------------------------------------------------------------------------
@@ -50,15 +51,15 @@ class IPC_EXPORT FileDescriptorSet
// Return the number of descriptors
unsigned size() const { return descriptors_.size(); }
// Return true if no unconsumed descriptors remain
- bool empty() const { return descriptors_.empty(); }
- // Fetch the nth descriptor from the beginning of the set. Code using this
- // /must/ access the descriptors in order, except that it may wrap from the
- // end to index 0 again.
+ bool empty() const { return 0 == size(); }
+ // Take the nth descriptor from the beginning of the set,
+ // transferring the ownership of the descriptor taken. Code using this
+ // /must/ access the descriptors in order, and must do it at most once.
//
// This interface is designed for the deserialising code as it doesn't
// support close flags.
// returns: file descriptor, or -1 on error
- int GetDescriptorAt(unsigned n) const;
+ base::PlatformFile TakeDescriptorAt(unsigned n);
// ---------------------------------------------------------------------------
@@ -69,9 +70,9 @@ class IPC_EXPORT FileDescriptorSet
// Fill an array with file descriptors without 'consuming' them. CommitAll
// must be called after these descriptors have been transmitted.
// buffer: (output) a buffer of, at least, size() integers.
- void GetDescriptors(int* buffer) const;
+ void PeekDescriptors(base::PlatformFile* buffer) const;
// This must be called after transmitting the descriptors returned by
- // GetDescriptors. It marks all the descriptors as consumed and closes those
+ // PeekDescriptors. It marks all the descriptors as consumed and closes those
// which are auto-close.
void CommitAll();
// Returns true if any contained file descriptors appear to be handles to a
@@ -79,7 +80,7 @@ class IPC_EXPORT FileDescriptorSet
bool ContainsDirectoryDescriptor() const;
// Fetch all filedescriptors with the "auto close" property.
// Used instead of CommitAll() when closing must be handled manually.
- void ReleaseFDsToClose(std::vector<int>* fds);
+ void ReleaseFDsToClose(std::vector<base::PlatformFile>* fds);
// ---------------------------------------------------------------------------
@@ -90,7 +91,7 @@ class IPC_EXPORT FileDescriptorSet
// Set the contents of the set from the given buffer. This set must be empty
// before calling. The auto-close flag is set on all the descriptors so that
// unconsumed descriptors are closed on destruction.
- void SetDescriptors(const int* buffer, unsigned count);
+ void AddDescriptorsToOwn(const base::PlatformFile* buffer, unsigned count);
// ---------------------------------------------------------------------------
@@ -103,7 +104,8 @@ class IPC_EXPORT FileDescriptorSet
// these descriptors are sent as control data. After sending, any descriptors
// with a true flag are closed. If this message has been received, then these
// are the descriptors which were received and all close flags are true.
- std::vector<base::FileDescriptor> descriptors_;
+ std::vector<base::PlatformFile> descriptors_;
+ ScopedVector<base::ScopedFD> owned_descriptors_;
// This contains the index of the next descriptor which should be consumed.
// It's used in a couple of ways. Firstly, at destruction we can check that