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

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

Issue 1678333003: Revert of [mojo-edk] Simplify multiprocess pipe bootstrap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « mojo/edk/system/node_channel.h ('k') | mojo/edk/system/node_controller.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 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/node_channel.h" 5 #include "mojo/edk/system/node_channel.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 11 matching lines...) Expand all
22 return t + (k - (t % k)) % k; 22 return t + (k - (t % k)) % k;
23 } 23 }
24 24
25 enum class MessageType : uint32_t { 25 enum class MessageType : uint32_t {
26 ACCEPT_CHILD, 26 ACCEPT_CHILD,
27 ACCEPT_PARENT, 27 ACCEPT_PARENT,
28 ADD_BROKER_CLIENT, 28 ADD_BROKER_CLIENT,
29 BROKER_CLIENT_ADDED, 29 BROKER_CLIENT_ADDED,
30 ACCEPT_BROKER_CLIENT, 30 ACCEPT_BROKER_CLIENT,
31 PORTS_MESSAGE, 31 PORTS_MESSAGE,
32 REQUEST_PORT_MERGE, 32 REQUEST_PORT_CONNECTION,
33 CONNECT_TO_PORT,
33 REQUEST_INTRODUCTION, 34 REQUEST_INTRODUCTION,
34 INTRODUCE, 35 INTRODUCE,
35 #if defined(OS_WIN) 36 #if defined(OS_WIN)
36 RELAY_PORTS_MESSAGE, 37 RELAY_PORTS_MESSAGE,
37 #endif 38 #endif
38 }; 39 };
39 40
40 struct Header { 41 struct Header {
41 MessageType type; 42 MessageType type;
42 uint32_t padding; 43 uint32_t padding;
(...skipping 23 matching lines...) Expand all
66 }; 67 };
67 68
68 // This data may be followed by a platform channel handle to the broker. If not, 69 // This data may be followed by a platform channel handle to the broker. If not,
69 // then the parent is the broker and its channel should be used as such. 70 // then the parent is the broker and its channel should be used as such.
70 struct AcceptBrokerClientData { 71 struct AcceptBrokerClientData {
71 ports::NodeName broker_name; 72 ports::NodeName broker_name;
72 }; 73 };
73 74
74 // This is followed by arbitrary payload data which is interpreted as a token 75 // This is followed by arbitrary payload data which is interpreted as a token
75 // string for port location. 76 // string for port location.
76 struct RequestPortMergeData { 77 struct RequestPortConnectionData {
77 ports::PortName connector_port_name; 78 ports::PortName connector_port_name;
78 }; 79 };
79 80
81 struct ConnectToPortData {
82 ports::PortName connector_port_name;
83 ports::PortName connectee_port_name;
84 };
85
80 // Used for both REQUEST_INTRODUCTION and INTRODUCE. 86 // Used for both REQUEST_INTRODUCTION and INTRODUCE.
81 // 87 //
82 // For INTRODUCE the message also includes a valid platform handle for a channel 88 // For INTRODUCE the message also includes a valid platform handle for a channel
83 // the receiver may use to communicate with the named node directly, or an 89 // the receiver may use to communicate with the named node directly, or an
84 // invalid platform handle if the node is unknown to the sender or otherwise 90 // invalid platform handle if the node is unknown to the sender or otherwise
85 // cannot be introduced. 91 // cannot be introduced.
86 struct IntroductionData { 92 struct IntroductionData {
87 ports::NodeName name; 93 ports::NodeName name;
88 }; 94 };
89 95
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 handles->size(), &data); 260 handles->size(), &data);
255 message->SetHandles(std::move(handles)); 261 message->SetHandles(std::move(handles));
256 data->broker_name = broker_name; 262 data->broker_name = broker_name;
257 WriteChannelMessage(std::move(message)); 263 WriteChannelMessage(std::move(message));
258 } 264 }
259 265
260 void NodeChannel::PortsMessage(Channel::MessagePtr message) { 266 void NodeChannel::PortsMessage(Channel::MessagePtr message) {
261 WriteChannelMessage(std::move(message)); 267 WriteChannelMessage(std::move(message));
262 } 268 }
263 269
264 void NodeChannel::RequestPortMerge(const ports::PortName& connector_port_name, 270 void NodeChannel::RequestPortConnection(
265 const std::string& token) { 271 const ports::PortName& connector_port_name,
266 RequestPortMergeData* data; 272 const std::string& token) {
273 RequestPortConnectionData* data;
267 Channel::MessagePtr message = CreateMessage( 274 Channel::MessagePtr message = CreateMessage(
268 MessageType::REQUEST_PORT_MERGE, 275 MessageType::REQUEST_PORT_CONNECTION,
269 sizeof(RequestPortMergeData) + token.size(), 0, &data); 276 sizeof(RequestPortConnectionData) + token.size(), 0, &data);
270 data->connector_port_name = connector_port_name; 277 data->connector_port_name = connector_port_name;
271 memcpy(data + 1, token.data(), token.size()); 278 memcpy(data + 1, token.data(), token.size());
272 WriteChannelMessage(std::move(message)); 279 WriteChannelMessage(std::move(message));
273 } 280 }
274 281
282 void NodeChannel::ConnectToPort(const ports::PortName& connector_port_name,
283 const ports::PortName& connectee_port_name) {
284 ConnectToPortData* data;
285 Channel::MessagePtr message = CreateMessage(
286 MessageType::CONNECT_TO_PORT, sizeof(ConnectToPortData), 0, &data);
287 data->connector_port_name = connector_port_name;
288 data->connectee_port_name = connectee_port_name;
289 WriteChannelMessage(std::move(message));
290 }
291
275 void NodeChannel::RequestIntroduction(const ports::NodeName& name) { 292 void NodeChannel::RequestIntroduction(const ports::NodeName& name) {
276 IntroductionData* data; 293 IntroductionData* data;
277 Channel::MessagePtr message = CreateMessage( 294 Channel::MessagePtr message = CreateMessage(
278 MessageType::REQUEST_INTRODUCTION, sizeof(IntroductionData), 0, &data); 295 MessageType::REQUEST_INTRODUCTION, sizeof(IntroductionData), 0, &data);
279 data->name = name; 296 data->name = name;
280 WriteChannelMessage(std::move(message)); 297 WriteChannelMessage(std::move(message));
281 } 298 }
282 299
283 void NodeChannel::Introduce(const ports::NodeName& name, 300 void NodeChannel::Introduce(const ports::NodeName& name,
284 ScopedPlatformHandle channel_handle) { 301 ScopedPlatformHandle channel_handle) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 case MessageType::PORTS_MESSAGE: { 445 case MessageType::PORTS_MESSAGE: {
429 size_t num_handles = handles ? handles->size() : 0; 446 size_t num_handles = handles ? handles->size() : 0;
430 Channel::MessagePtr message( 447 Channel::MessagePtr message(
431 new Channel::Message(payload_size, num_handles)); 448 new Channel::Message(payload_size, num_handles));
432 message->SetHandles(std::move(handles)); 449 message->SetHandles(std::move(handles));
433 memcpy(message->mutable_payload(), payload, payload_size); 450 memcpy(message->mutable_payload(), payload, payload_size);
434 delegate_->OnPortsMessage(std::move(message)); 451 delegate_->OnPortsMessage(std::move(message));
435 break; 452 break;
436 } 453 }
437 454
438 case MessageType::REQUEST_PORT_MERGE: { 455 case MessageType::REQUEST_PORT_CONNECTION: {
439 const RequestPortMergeData* data; 456 const RequestPortConnectionData* data;
440 GetMessagePayload(payload, &data); 457 GetMessagePayload(payload, &data);
441 458
442 const char* token_data = reinterpret_cast<const char*>(data + 1); 459 const char* token_data = reinterpret_cast<const char*>(data + 1);
443 const size_t token_size = payload_size - sizeof(*data) - sizeof(Header); 460 const size_t token_size = payload_size - sizeof(*data) - sizeof(Header);
444 std::string token(token_data, token_size); 461 std::string token(token_data, token_size);
445 462
446 delegate_->OnRequestPortMerge(remote_node_name_, 463 delegate_->OnRequestPortConnection(remote_node_name_,
447 data->connector_port_name, token); 464 data->connector_port_name, token);
448 break; 465 break;
449 } 466 }
450 467
468 case MessageType::CONNECT_TO_PORT: {
469 const ConnectToPortData* data;
470 GetMessagePayload(payload, &data);
471 delegate_->OnConnectToPort(remote_node_name_, data->connector_port_name,
472 data->connectee_port_name);
473 break;
474 }
475
451 case MessageType::REQUEST_INTRODUCTION: { 476 case MessageType::REQUEST_INTRODUCTION: {
452 const IntroductionData* data; 477 const IntroductionData* data;
453 GetMessagePayload(payload, &data); 478 GetMessagePayload(payload, &data);
454 delegate_->OnRequestIntroduction(remote_node_name_, data->name); 479 delegate_->OnRequestIntroduction(remote_node_name_, data->name);
455 break; 480 break;
456 } 481 }
457 482
458 case MessageType::INTRODUCE: { 483 case MessageType::INTRODUCE: {
459 const IntroductionData* data; 484 const IntroductionData* data;
460 GetMessagePayload(payload, &data); 485 GetMessagePayload(payload, &data);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 567
543 base::AutoLock lock(channel_lock_); 568 base::AutoLock lock(channel_lock_);
544 if (!channel_) 569 if (!channel_)
545 DLOG(ERROR) << "Dropping message on closed channel."; 570 DLOG(ERROR) << "Dropping message on closed channel.";
546 else 571 else
547 channel_->Write(std::move(message)); 572 channel_->Write(std::move(message));
548 } 573 }
549 574
550 } // namespace edk 575 } // namespace edk
551 } // namespace mojo 576 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/node_channel.h ('k') | mojo/edk/system/node_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698