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

Unified Diff: chrome/common/ipc_message.cc

Issue 20275: POSIX: Clean up DescriptorSet (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 | « chrome/common/ipc_message.h ('k') | chrome/common/ipc_message_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/ipc_message.cc
diff --git a/chrome/common/ipc_message.cc b/chrome/common/ipc_message.cc
index 848f8bc00d097b02e51c99222ae88dfc87d20649..9a15f1c653795ab02829fbb688e9cd6d834bed3b 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
« no previous file with comments | « chrome/common/ipc_message.h ('k') | chrome/common/ipc_message_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698