1 // Copyright 2014 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/bindings/sync_dispatcher.h"
9 #include "mojo/public/bindings/message.h"
13 bool WaitForMessageAndDispatch(MessagePipeHandle handle,
14 mojo::MessageReceiver* receiver) {
15 uint32_t num_bytes = 0, num_handles = 0;
17 MojoResult rv = ReadMessageRaw(handle,
22 MOJO_READ_MESSAGE_FLAG_NONE);
23 if (rv == MOJO_RESULT_RESOURCE_EXHAUSTED)
25 if (rv != MOJO_RESULT_SHOULD_WAIT)
27 rv = Wait(handle, MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE);
28 if (rv != MOJO_RESULT_OK)
33 message.data = static_cast<MessageData*>(malloc(num_bytes));
34 message.handles.resize(num_handles);
37 ReadMessageRaw(handle,
40 message.handles.empty()
42 : reinterpret_cast<MojoHandle*>(&message.handles[0]),
44 MOJO_READ_MESSAGE_FLAG_NONE);
45 if (rv != MOJO_RESULT_OK)
47 return receiver->Accept(&message);