1 // Copyright (c) 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.
7 #include "base/basictypes.h"
8 #include "mojo/public/system/core.h"
9 #include "mojo/system/core_impl.h"
15 #define SAMPLE_APP_EXPORT __declspec(dllexport)
18 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
21 char* ReadStringFromPipe(mojo::Handle pipe
) {
24 MojoResult result
= mojo::ReadMessage(pipe
, buf
, &len
, NULL
, NULL
,
25 MOJO_READ_MESSAGE_FLAG_NONE
);
26 if (result
== MOJO_RESULT_RESOURCE_EXHAUSTED
) {
28 result
= mojo::ReadMessage(pipe
, buf
, &len
, NULL
, NULL
,
29 MOJO_READ_MESSAGE_FLAG_NONE
);
31 if (result
< MOJO_RESULT_OK
) {
40 class SampleMessageWaiter
{
42 explicit SampleMessageWaiter(mojo::Handle pipe
) : pipe_(pipe
) {}
43 ~SampleMessageWaiter() {}
46 char* string
= ReadStringFromPipe(pipe_
);
48 printf("Read string from pipe: %s\n", string
);
55 MojoResult result
= mojo::Wait(pipe_
, MOJO_WAIT_FLAG_READABLE
, 100);
56 if (result
< MOJO_RESULT_OK
) {
66 DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter
);
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL
MojoMain(
71 SampleMessageWaiter(pipe
).WaitAndRead();
72 return MOJO_RESULT_OK
;