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

Side by Side Diff: mojo/edk/system/channel_posix.cc

Issue 2710193003: Adding a new message type to the Mojo channel. (Closed)
Patch Set: Fixed Mac tests + sync Created 3 years, 9 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 | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/channel_unittest.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 std::vector<int> fds; 380 std::vector<int> fds;
381 for (auto& handle : *handles) 381 for (auto& handle : *handles)
382 fds.push_back(handle.handle); 382 fds.push_back(handle.handle);
383 { 383 {
384 base::AutoLock l(handles_to_close_lock_); 384 base::AutoLock l(handles_to_close_lock_);
385 for (auto& handle : *handles) 385 for (auto& handle : *handles)
386 handles_to_close_->push_back(handle); 386 handles_to_close_->push_back(handle);
387 } 387 }
388 MessagePtr fds_message( 388 MessagePtr fds_message(
389 new Channel::Message(sizeof(fds[0]) * fds.size(), 0, 389 new Channel::Message(sizeof(fds[0]) * fds.size(), 0,
390 Message::Header::MessageType::HANDLES_SENT)); 390 Message::MessageType::HANDLES_SENT));
391 memcpy(fds_message->mutable_payload(), fds.data(), 391 memcpy(fds_message->mutable_payload(), fds.data(),
392 sizeof(fds[0]) * fds.size()); 392 sizeof(fds[0]) * fds.size());
393 outgoing_messages_.emplace_back(std::move(fds_message), 0); 393 outgoing_messages_.emplace_back(std::move(fds_message), 0);
394 handles->clear(); 394 handles->clear();
395 #else 395 #else
396 handles.reset(); 396 handles.reset();
397 #endif // defined(OS_MACOSX) 397 #endif // defined(OS_MACOSX)
398 } 398 }
399 } else { 399 } else {
400 result = PlatformChannelWrite(handle_.get(), message_view.data(), 400 result = PlatformChannelWrite(handle_.get(), message_view.data(),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 messages.pop_back(); 455 messages.pop_back();
456 } 456 }
457 return true; 457 return true;
458 } 458 }
459 } 459 }
460 460
461 return true; 461 return true;
462 } 462 }
463 463
464 #if defined(OS_MACOSX) 464 #if defined(OS_MACOSX)
465 bool OnControlMessage(Message::Header::MessageType message_type, 465 bool OnControlMessage(Message::MessageType message_type,
466 const void* payload, 466 const void* payload,
467 size_t payload_size, 467 size_t payload_size,
468 ScopedPlatformHandleVectorPtr handles) override { 468 ScopedPlatformHandleVectorPtr handles) override {
469 switch (message_type) { 469 switch (message_type) {
470 case Message::Header::MessageType::HANDLES_SENT: { 470 case Message::MessageType::HANDLES_SENT: {
471 if (payload_size == 0) 471 if (payload_size == 0)
472 break; 472 break;
473 MessagePtr message(new Channel::Message( 473 MessagePtr message(new Channel::Message(
474 payload_size, 0, Message::Header::MessageType::HANDLES_SENT_ACK)); 474 payload_size, 0, Message::MessageType::HANDLES_SENT_ACK));
475 memcpy(message->mutable_payload(), payload, payload_size); 475 memcpy(message->mutable_payload(), payload, payload_size);
476 Write(std::move(message)); 476 Write(std::move(message));
477 return true; 477 return true;
478 } 478 }
479 479
480 case Message::Header::MessageType::HANDLES_SENT_ACK: { 480 case Message::MessageType::HANDLES_SENT_ACK: {
481 size_t num_fds = payload_size / sizeof(int); 481 size_t num_fds = payload_size / sizeof(int);
482 if (num_fds == 0 || payload_size % sizeof(int) != 0) 482 if (num_fds == 0 || payload_size % sizeof(int) != 0)
483 break; 483 break;
484 484
485 const int* fds = reinterpret_cast<const int*>(payload); 485 const int* fds = reinterpret_cast<const int*>(payload);
486 if (!CloseHandles(fds, num_fds)) 486 if (!CloseHandles(fds, num_fds))
487 break; 487 break;
488 return true; 488 return true;
489 } 489 }
490 490
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // static 561 // static
562 scoped_refptr<Channel> Channel::Create( 562 scoped_refptr<Channel> Channel::Create(
563 Delegate* delegate, 563 Delegate* delegate,
564 ScopedPlatformHandle platform_handle, 564 ScopedPlatformHandle platform_handle,
565 scoped_refptr<base::TaskRunner> io_task_runner) { 565 scoped_refptr<base::TaskRunner> io_task_runner) {
566 return new ChannelPosix(delegate, std::move(platform_handle), io_task_runner); 566 return new ChannelPosix(delegate, std::move(platform_handle), io_task_runner);
567 } 567 }
568 568
569 } // namespace edk 569 } // namespace edk
570 } // namespace mojo 570 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698