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

Side by Side Diff: ipc/ipc_channel_nacl.cc

Issue 583473002: IPC: Get rid of FileDescriptor usage from FileDescriptorSet and Message (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « ipc/file_descriptor_set_posix_unittest.cc ('k') | ipc/ipc_channel_posix.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ipc/ipc_channel_nacl.h" 5 #include "ipc/ipc_channel_nacl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 // Write out all the messages. The trusted implementation is guaranteed to not 277 // Write out all the messages. The trusted implementation is guaranteed to not
278 // block. See NaClIPCAdapter::Send for the implementation of imc_sendmsg. 278 // block. See NaClIPCAdapter::Send for the implementation of imc_sendmsg.
279 while (!output_queue_.empty()) { 279 while (!output_queue_.empty()) {
280 linked_ptr<Message> msg = output_queue_.front(); 280 linked_ptr<Message> msg = output_queue_.front();
281 output_queue_.pop_front(); 281 output_queue_.pop_front();
282 282
283 int fds[FileDescriptorSet::kMaxDescriptorsPerMessage]; 283 int fds[FileDescriptorSet::kMaxDescriptorsPerMessage];
284 const size_t num_fds = msg->file_descriptor_set()->size(); 284 const size_t num_fds = msg->file_descriptor_set()->size();
285 DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage); 285 DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage);
286 msg->file_descriptor_set()->GetDescriptors(fds); 286 msg->file_descriptor_set()->PeekDescriptors(fds);
287 287
288 NaClAbiNaClImcMsgIoVec iov = { 288 NaClAbiNaClImcMsgIoVec iov = {
289 const_cast<void*>(msg->data()), msg->size() 289 const_cast<void*>(msg->data()), msg->size()
290 }; 290 };
291 NaClAbiNaClImcMsgHdr msgh = { &iov, 1, fds, num_fds }; 291 NaClAbiNaClImcMsgHdr msgh = { &iov, 1, fds, num_fds };
292 ssize_t bytes_written = imc_sendmsg(pipe_, &msgh, 0); 292 ssize_t bytes_written = imc_sendmsg(pipe_, &msgh, 0);
293 293
294 DCHECK(bytes_written); // The trusted side shouldn't return 0. 294 DCHECK(bytes_written); // The trusted side shouldn't return 0.
295 if (bytes_written < 0) { 295 if (bytes_written < 0) {
296 // The trusted side should only ever give us an error of EPIPE. We 296 // The trusted side should only ever give us an error of EPIPE. We
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 bool ChannelNacl::WillDispatchInputMessage(Message* msg) { 351 bool ChannelNacl::WillDispatchInputMessage(Message* msg) {
352 uint16 header_fds = msg->header()->num_fds; 352 uint16 header_fds = msg->header()->num_fds;
353 CHECK(header_fds == input_fds_.size()); 353 CHECK(header_fds == input_fds_.size());
354 if (header_fds == 0) 354 if (header_fds == 0)
355 return true; // Nothing to do. 355 return true; // Nothing to do.
356 356
357 // The shenaniganery below with &foo.front() requires input_fds_ to have 357 // The shenaniganery below with &foo.front() requires input_fds_ to have
358 // contiguous underlying storage (such as a simple array or a std::vector). 358 // contiguous underlying storage (such as a simple array or a std::vector).
359 // This is why the header warns not to make input_fds_ a deque<>. 359 // This is why the header warns not to make input_fds_ a deque<>.
360 msg->file_descriptor_set()->SetDescriptors(&input_fds_.front(), 360 msg->file_descriptor_set()->AddDescriptorsToOwn(&input_fds_.front(),
361 header_fds); 361 header_fds);
362 input_fds_.clear(); 362 input_fds_.clear();
363 return true; 363 return true;
364 } 364 }
365 365
366 bool ChannelNacl::DidEmptyInputBuffers() { 366 bool ChannelNacl::DidEmptyInputBuffers() {
367 // When the input data buffer is empty, the fds should be too. 367 // When the input data buffer is empty, the fds should be too.
368 return input_fds_.empty(); 368 return input_fds_.empty();
369 } 369 }
370 370
371 void ChannelNacl::HandleInternalMessage(const Message& msg) { 371 void ChannelNacl::HandleInternalMessage(const Message& msg) {
372 // The trusted side IPC::Channel should handle the "hello" handshake; we 372 // The trusted side IPC::Channel should handle the "hello" handshake; we
373 // should not receive the "Hello" message. 373 // should not receive the "Hello" message.
374 NOTREACHED(); 374 NOTREACHED();
375 } 375 }
376 376
377 // Channel's methods 377 // Channel's methods
378 378
379 // static 379 // static
380 scoped_ptr<Channel> Channel::Create( 380 scoped_ptr<Channel> Channel::Create(
381 const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { 381 const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) {
382 return scoped_ptr<Channel>( 382 return scoped_ptr<Channel>(
383 new ChannelNacl(channel_handle, mode, listener)); 383 new ChannelNacl(channel_handle, mode, listener));
384 } 384 }
385 385
386 } // namespace IPC 386 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/file_descriptor_set_posix_unittest.cc ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698