Index: ipc/ipc_channel_nacl.cc |
diff --git a/ipc/ipc_channel_nacl.cc b/ipc/ipc_channel_nacl.cc |
index 0cea37315790f6fa767b88d63decdb51f7dff4ee..867eb97cb5ad5b65f373d5bb01fc94d10c56038c 100644 |
--- a/ipc/ipc_channel_nacl.cc |
+++ b/ipc/ipc_channel_nacl.cc |
@@ -23,7 +23,6 @@ |
#include "ipc/ipc_listener.h" |
#include "ipc/ipc_logging.h" |
#include "ipc/ipc_message_attachment_set.h" |
-#include "ipc/ipc_platform_file_attachment_posix.h" |
#include "native_client/src/public/imc_syscalls.h" |
#include "native_client/src/public/imc_types.h" |
@@ -226,11 +225,8 @@ |
data->swap(contents->data); |
read_queue_.push_back(data); |
- input_attachments_.reserve(contents->fds.size()); |
- for (int fd : contents->fds) { |
- input_attachments_.push_back( |
- new internal::PlatformFileAttachment(base::ScopedFD(fd))); |
- } |
+ input_fds_.insert(input_fds_.end(), |
+ contents->fds.begin(), contents->fds.end()); |
contents->fds.clear(); |
// In POSIX, we would be told when there are bytes to read by implementing |
@@ -278,22 +274,16 @@ |
linked_ptr<Message> msg = output_queue_.front(); |
output_queue_.pop_front(); |
- const size_t num_fds = msg->attachment_set()->size(); |
+ int fds[MessageAttachmentSet::kMaxDescriptorsPerMessage]; |
+ const size_t num_fds = |
+ msg->attachment_set()->num_non_brokerable_attachments(); |
DCHECK(num_fds <= MessageAttachmentSet::kMaxDescriptorsPerMessage); |
- std::vector<int> fds; |
- fds.reserve(num_fds); |
- for (size_t i = 0; i < num_fds; i++) { |
- scoped_refptr<MessageAttachment> attachment = |
- msg->attachment_set()->GetAttachmentAt(i); |
- DCHECK_EQ(MessageAttachment::Type::PLATFORM_FILE, attachment->GetType()); |
- fds.push_back(static_cast<internal::PlatformFileAttachment&>(*attachment) |
- .TakePlatformFile()); |
- } |
+ msg->attachment_set()->PeekDescriptors(fds); |
NaClAbiNaClImcMsgIoVec iov = { |
const_cast<void*>(msg->data()), msg->size() |
}; |
- NaClAbiNaClImcMsgHdr msgh = {&iov, 1, fds.data(), num_fds}; |
+ NaClAbiNaClImcMsgHdr msgh = { &iov, 1, fds, num_fds }; |
ssize_t bytes_written = imc_sendmsg(pipe_, &msgh, 0); |
DCHECK(bytes_written); // The trusted side shouldn't return 0. |
@@ -357,22 +347,23 @@ |
return true; |
} |
-bool ChannelNacl::GetAttachments(Message* msg) { |
+bool ChannelNacl::GetNonBrokeredAttachments(Message* msg) { |
uint16_t header_fds = msg->header()->num_fds; |
- CHECK(header_fds == input_attachments_.size()); |
+ CHECK(header_fds == input_fds_.size()); |
if (header_fds == 0) |
return true; // Nothing to do. |
- for (auto& attachment : input_attachments_) { |
- msg->attachment_set()->AddAttachment(std::move(attachment)); |
- } |
- input_attachments_.clear(); |
+ // The shenaniganery below with &foo.front() requires input_fds_ to have |
+ // contiguous underlying storage (such as a simple array or a std::vector). |
+ // This is why the header warns not to make input_fds_ a deque<>. |
+ msg->attachment_set()->AddDescriptorsToOwn(&input_fds_.front(), header_fds); |
+ input_fds_.clear(); |
return true; |
} |
bool ChannelNacl::DidEmptyInputBuffers() { |
- // When the input data buffer is empty, the attachments should be too. |
- return input_attachments_.empty(); |
+ // When the input data buffer is empty, the fds should be too. |
+ return input_fds_.empty(); |
} |
void ChannelNacl::HandleInternalMessage(const Message& msg) { |