OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/public/cpp/bindings/message.h" | 5 #include "mojo/public/cpp/bindings/message.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 void Message::CloseHandles() { | 41 void Message::CloseHandles() { |
42 for (std::vector<Handle>::iterator it = handles_.begin(); | 42 for (std::vector<Handle>::iterator it = handles_.begin(); |
43 it != handles_.end(); ++it) { | 43 it != handles_.end(); ++it) { |
44 if (it->is_valid()) | 44 if (it->is_valid()) |
45 CloseRaw(*it); | 45 CloseRaw(*it); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 MojoResult ReadAndDispatchMessage(MessagePipeHandle handle, | 49 MojoResult ReadMessage(MessagePipeHandle handle, Message* message) { |
50 MessageReceiver* receiver, | |
51 bool* receiver_result) { | |
52 MojoResult rv; | 50 MojoResult rv; |
53 | 51 |
54 uint32_t num_bytes = 0, num_handles = 0; | 52 uint32_t num_bytes = 0, num_handles = 0; |
55 rv = ReadMessageRaw(handle, | 53 rv = ReadMessageRaw(handle, |
56 nullptr, | 54 nullptr, |
57 &num_bytes, | 55 &num_bytes, |
58 nullptr, | 56 nullptr, |
59 &num_handles, | 57 &num_handles, |
60 MOJO_READ_MESSAGE_FLAG_NONE); | 58 MOJO_READ_MESSAGE_FLAG_NONE); |
61 if (rv != MOJO_RESULT_RESOURCE_EXHAUSTED) | 59 if (rv != MOJO_RESULT_RESOURCE_EXHAUSTED) |
62 return rv; | 60 return rv; |
63 | 61 |
64 Message message; | 62 message->Initialize(num_bytes, false /* zero_initialized */); |
65 message.Initialize(num_bytes, false /* zero_initialized */); | |
66 | 63 |
67 void* mutable_data = message.buffer()->Allocate(num_bytes); | 64 void* mutable_data = message->buffer()->Allocate(num_bytes); |
68 message.mutable_handles()->resize(num_handles); | 65 message->mutable_handles()->resize(num_handles); |
69 | 66 |
70 rv = ReadMessageRaw( | 67 rv = ReadMessageRaw( |
71 handle, | 68 handle, mutable_data, &num_bytes, |
72 mutable_data, | 69 message->mutable_handles()->empty() |
73 &num_bytes, | |
74 message.mutable_handles()->empty() | |
75 ? nullptr | 70 ? nullptr |
76 : reinterpret_cast<MojoHandle*>(message.mutable_handles()->data()), | 71 : reinterpret_cast<MojoHandle*>(message->mutable_handles()->data()), |
77 &num_handles, | 72 &num_handles, MOJO_READ_MESSAGE_FLAG_NONE); |
78 MOJO_READ_MESSAGE_FLAG_NONE); | |
79 if (receiver && rv == MOJO_RESULT_OK) | |
80 *receiver_result = receiver->Accept(&message); | |
81 | |
82 return rv; | 73 return rv; |
83 } | 74 } |
84 | 75 |
85 } // namespace mojo | 76 } // namespace mojo |
OLD | NEW |