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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "base/basictypes.h" | |
8 #include "mojo/public/system/core.h" | 7 #include "mojo/public/system/core.h" |
| 8 #include "mojo/public/system/macros.h" |
9 #include "mojo/system/core_impl.h" | 9 #include "mojo/system/core_impl.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #if !defined(CDECL) | 12 #if !defined(CDECL) |
13 #define CDECL __cdecl | 13 #define CDECL __cdecl |
14 #endif | 14 #endif |
15 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 15 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
16 #else | 16 #else |
17 #define CDECL | 17 #define CDECL |
18 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 18 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
(...skipping 26 matching lines...) Expand all Loading... |
45 void Read() { | 45 void Read() { |
46 char* string = ReadStringFromPipe(pipe_); | 46 char* string = ReadStringFromPipe(pipe_); |
47 if (string) { | 47 if (string) { |
48 printf("Read string from pipe: %s\n", string); | 48 printf("Read string from pipe: %s\n", string); |
49 delete[] string; | 49 delete[] string; |
50 string = NULL; | 50 string = NULL; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 void WaitAndRead() { | 54 void WaitAndRead() { |
55 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100); | 55 for (int i = 0; i < 100;) { |
56 if (result < MOJO_RESULT_OK) { | 56 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100); |
57 // Failure... | 57 if (result < MOJO_RESULT_OK) { |
| 58 // Failure... |
| 59 continue; |
| 60 } |
| 61 ++i; |
| 62 Read(); |
58 } | 63 } |
59 | |
60 Read(); | |
61 } | 64 } |
62 | 65 |
63 private: | 66 private: |
| 67 mojo::Handle pipe_; |
64 | 68 |
65 mojo::Handle pipe_; | 69 MOJO_DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter); |
66 DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter); | |
67 }; | 70 }; |
68 | 71 |
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( | 72 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
70 mojo::Handle pipe) { | 73 mojo::Handle pipe) { |
71 SampleMessageWaiter(pipe).WaitAndRead(); | 74 SampleMessageWaiter(pipe).WaitAndRead(); |
72 return MOJO_RESULT_OK; | 75 return MOJO_RESULT_OK; |
73 } | 76 } |
OLD | NEW |