1 // Copyright 2013 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.
5 #include "mojo/public/cpp/bindings/message.h"
11 #include "mojo/public/cpp/environment/logging.h"
23 for (std::vector
<Handle
>::iterator it
= handles_
.begin();
24 it
!= handles_
.end(); ++it
) {
30 void Message::AllocUninitializedData(uint32_t num_bytes
) {
32 data_num_bytes_
= num_bytes
;
33 data_
= static_cast<internal::MessageData
*>(malloc(num_bytes
));
36 void Message::AdoptData(uint32_t num_bytes
, internal::MessageData
* data
) {
38 data_num_bytes_
= num_bytes
;
42 void Message::Swap(Message
* other
) {
43 std::swap(data_num_bytes_
, other
->data_num_bytes_
);
44 std::swap(data_
, other
->data_
);
45 std::swap(handles_
, other
->handles_
);
48 MojoResult
ReadAndDispatchMessage(MessagePipeHandle handle
,
49 MessageReceiver
* receiver
,
50 bool* receiver_result
) {
53 uint32_t num_bytes
= 0, num_handles
= 0;
54 rv
= ReadMessageRaw(handle
,
59 MOJO_READ_MESSAGE_FLAG_NONE
);
60 if (rv
!= MOJO_RESULT_RESOURCE_EXHAUSTED
)
64 message
.AllocUninitializedData(num_bytes
);
65 message
.mutable_handles()->resize(num_handles
);
67 rv
= ReadMessageRaw(handle
,
68 message
.mutable_data(),
70 message
.mutable_handles()->empty()
72 : reinterpret_cast<MojoHandle
*>(
73 &message
.mutable_handles()->front()),
75 MOJO_READ_MESSAGE_FLAG_NONE
);
76 if (receiver
&& rv
== MOJO_RESULT_OK
)
77 *receiver_result
= receiver
->Accept(&message
);