diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-12 04:05:28 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-12 04:05:28 +0000 |
commit | 7135bb043af7f66b5ed36e71775e9d1835da7420 (patch) | |
tree | 41c3ee7d52df762392ee36fd03cea80761b03015 /chrome/common/ipc_message.cc | |
parent | e707d5e60b2191d3ffde90edcbafc01d8d7f7590 (diff) | |
download | chromium_src-7135bb043af7f66b5ed36e71775e9d1835da7420.zip chromium_src-7135bb043af7f66b5ed36e71775e9d1835da7420.tar.gz chromium_src-7135bb043af7f66b5ed36e71775e9d1835da7420.tar.bz2 |
POSIX: Clean up DescriptorSet
In general, the IPC Message objects are const and the iterator state is a void*
kept by the code which is doing the deserialisation.
However, now that we have an array of file descriptors, the index of the next
file descriptor is part of the iteration state and is kept /inside/ the Message
(in the DescriptorSet). This means that it's a mutable member, which is never
too nice and also, since the logging functions want to parse a message multiple
times, we've had to turn off returning an error when one runs off the end of
the array.
Also, the Message copy constructor and assignment function alters the /source/
Message, by stealing all of its descriptors
This patch encodes the index of each file descriptor on the wire. So the state
is moved from inside the DescriptorSet into the serialised data.
Additionally, the DescriptorSet is made into a lazyily created scoped_refptr,
solving the problems with copying messages.
Review URL: http://codereview.chromium.org/20275
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9644 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/ipc_message.cc')
-rw-r--r-- | chrome/common/ipc_message.cc | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/chrome/common/ipc_message.cc b/chrome/common/ipc_message.cc index 848f8bc..9a15f1c 100644 --- a/chrome/common/ipc_message.cc +++ b/chrome/common/ipc_message.cc @@ -7,6 +7,10 @@ #include "base/logging.h" #include "build/build_config.h" +#if defined(OS_POSIX) +#include "chrome/common/descriptor_set_posix.h" +#endif + namespace IPC { //------------------------------------------------------------------------------ @@ -41,7 +45,7 @@ Message::Message(const char* data, int data_len) : Pickle(data, data_len) { Message::Message(const Message& other) : Pickle(other) { InitLoggingVariables(); #if defined(OS_POSIX) - descriptor_set_.TakeFrom(&other.descriptor_set_); + descriptor_set_ = other.descriptor_set_; #endif } @@ -56,7 +60,7 @@ void Message::InitLoggingVariables() { Message& Message::operator=(const Message& other) { *static_cast<Pickle*>(this) = other; #if defined(OS_POSIX) - descriptor_set_.TakeFrom(&other.descriptor_set_); + descriptor_set_ = other.descriptor_set_; #endif return *this; } @@ -82,5 +86,40 @@ void Message::set_received_time(int64 time) const { } #endif +#if defined(OS_POSIX) +bool Message::WriteFileDescriptor(const base::FileDescriptor& descriptor) { + // We write the index of the descriptor so that we don't have to + // keep the current descriptor as extra decoding state when deserialising. + WriteInt(descriptor_set()->size()); + if (descriptor.auto_close) { + return descriptor_set()->AddAndAutoClose(descriptor.fd); + } else { + return descriptor_set()->Add(descriptor.fd); + } +} + +bool Message::ReadFileDescriptor(void** iter, + base::FileDescriptor* descriptor) const { + int descriptor_index; + if (!ReadInt(iter, &descriptor_index)) + return false; + + DescriptorSet* descriptor_set = descriptor_set_.get(); + if (!descriptor_set) + return false; + + descriptor->fd = descriptor_set->GetDescriptorAt(descriptor_index); + descriptor->auto_close = false; + + return descriptor->fd >= 0; +} + +void Message::EnsureDescriptorSet() { + if (descriptor_set_.get() == NULL) + descriptor_set_ = new DescriptorSet; +} + +#endif + } // namespace IPC |