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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/ipc_message.h" 5 #include "chrome/common/ipc_message.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(OS_POSIX)
11 #include "chrome/common/descriptor_set_posix.h"
12 #endif
13
10 namespace IPC { 14 namespace IPC {
11 15
12 //------------------------------------------------------------------------------ 16 //------------------------------------------------------------------------------
13 17
14 Message::~Message() { 18 Message::~Message() {
15 } 19 }
16 20
17 Message::Message() 21 Message::Message()
18 : Pickle(sizeof(Header)) { 22 : Pickle(sizeof(Header)) {
19 header()->routing = header()->type = header()->flags = 0; 23 header()->routing = header()->type = header()->flags = 0;
(...skipping 14 matching lines...) Expand all
34 InitLoggingVariables(); 38 InitLoggingVariables();
35 } 39 }
36 40
37 Message::Message(const char* data, int data_len) : Pickle(data, data_len) { 41 Message::Message(const char* data, int data_len) : Pickle(data, data_len) {
38 InitLoggingVariables(); 42 InitLoggingVariables();
39 } 43 }
40 44
41 Message::Message(const Message& other) : Pickle(other) { 45 Message::Message(const Message& other) : Pickle(other) {
42 InitLoggingVariables(); 46 InitLoggingVariables();
43 #if defined(OS_POSIX) 47 #if defined(OS_POSIX)
44 descriptor_set_.TakeFrom(&other.descriptor_set_); 48 descriptor_set_ = other.descriptor_set_;
45 #endif 49 #endif
46 } 50 }
47 51
48 void Message::InitLoggingVariables() { 52 void Message::InitLoggingVariables() {
49 #ifdef IPC_MESSAGE_LOG_ENABLED 53 #ifdef IPC_MESSAGE_LOG_ENABLED
50 received_time_ = 0; 54 received_time_ = 0;
51 dont_log_ = false; 55 dont_log_ = false;
52 log_data_ = NULL; 56 log_data_ = NULL;
53 #endif 57 #endif
54 } 58 }
55 59
56 Message& Message::operator=(const Message& other) { 60 Message& Message::operator=(const Message& other) {
57 *static_cast<Pickle*>(this) = other; 61 *static_cast<Pickle*>(this) = other;
58 #if defined(OS_POSIX) 62 #if defined(OS_POSIX)
59 descriptor_set_.TakeFrom(&other.descriptor_set_); 63 descriptor_set_ = other.descriptor_set_;
60 #endif 64 #endif
61 return *this; 65 return *this;
62 } 66 }
63 67
64 #ifdef IPC_MESSAGE_LOG_ENABLED 68 #ifdef IPC_MESSAGE_LOG_ENABLED
65 void Message::set_sent_time(int64 time) { 69 void Message::set_sent_time(int64 time) {
66 DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0); 70 DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0);
67 header()->flags |= HAS_SENT_TIME_BIT; 71 header()->flags |= HAS_SENT_TIME_BIT;
68 WriteInt64(time); 72 WriteInt64(time);
69 } 73 }
70 74
71 int64 Message::sent_time() const { 75 int64 Message::sent_time() const {
72 if ((header()->flags & HAS_SENT_TIME_BIT) == 0) 76 if ((header()->flags & HAS_SENT_TIME_BIT) == 0)
73 return 0; 77 return 0;
74 78
75 const char* data = end_of_payload(); 79 const char* data = end_of_payload();
76 data -= sizeof(int64); 80 data -= sizeof(int64);
77 return *(reinterpret_cast<const int64*>(data)); 81 return *(reinterpret_cast<const int64*>(data));
78 } 82 }
79 83
80 void Message::set_received_time(int64 time) const { 84 void Message::set_received_time(int64 time) const {
81 received_time_ = time; 85 received_time_ = time;
82 } 86 }
83 #endif 87 #endif
84 88
89 #if defined(OS_POSIX)
90 bool Message::WriteFileDescriptor(const base::FileDescriptor& descriptor) {
91 // We write the index of the descriptor so that we don't have to
92 // keep the current descriptor as extra decoding state when deserialising.
93 WriteInt(descriptor_set()->size());
94 if (descriptor.auto_close) {
95 return descriptor_set()->AddAndAutoClose(descriptor.fd);
96 } else {
97 return descriptor_set()->Add(descriptor.fd);
98 }
99 }
100
101 bool Message::ReadFileDescriptor(void** iter,
102 base::FileDescriptor* descriptor) const {
103 int descriptor_index;
104 if (!ReadInt(iter, &descriptor_index))
105 return false;
106
107 DescriptorSet* descriptor_set = descriptor_set_.get();
108 if (!descriptor_set)
109 return false;
110
111 descriptor->fd = descriptor_set->GetDescriptorAt(descriptor_index);
112 descriptor->auto_close = false;
113
114 return descriptor->fd >= 0;
115 }
116
117 void Message::EnsureDescriptorSet() {
118 if (descriptor_set_.get() == NULL)
119 descriptor_set_ = new DescriptorSet;
120 }
121
122 #endif
123
85 } // namespace IPC 124 } // namespace IPC
86 125
OLDNEW
« 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