• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "mojo/core/data_pipe_control_message.h"
6 
7 #include "mojo/core/node_controller.h"
8 #include "mojo/core/ports/event.h"
9 #include "mojo/core/user_message_impl.h"
10 
11 namespace mojo {
12 namespace core {
13 
SendDataPipeControlMessage(NodeController * node_controller,const ports::PortRef & port,DataPipeCommand command,uint32_t num_bytes)14 void SendDataPipeControlMessage(NodeController* node_controller,
15                                 const ports::PortRef& port,
16                                 DataPipeCommand command,
17                                 uint32_t num_bytes) {
18   std::unique_ptr<ports::UserMessageEvent> event;
19   MojoResult result = UserMessageImpl::CreateEventForNewSerializedMessage(
20       sizeof(DataPipeControlMessage), nullptr, 0, &event);
21   DCHECK_EQ(MOJO_RESULT_OK, result);
22   DCHECK(event);
23 
24   DataPipeControlMessage* data = static_cast<DataPipeControlMessage*>(
25       event->GetMessage<UserMessageImpl>()->user_payload());
26   data->command = command;
27   data->num_bytes = num_bytes;
28 
29   int rv = node_controller->SendUserMessage(port, std::move(event));
30   if (rv != ports::OK && rv != ports::ERROR_PORT_PEER_CLOSED) {
31     DLOG(ERROR) << "Unexpected failure sending data pipe control message: "
32                 << rv;
33   }
34 }
35 
36 }  // namespace core
37 }  // namespace mojo
38