Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: mojo/shell/sample_app.cc

Issue 25895002: Simple shell that loads a dll and calls an entrypoint function passing in a handle to a pipe create… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Close handles to the message pipe. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include <stdio.h>
6
7 #include "base/basictypes.h"
8 #include "mojo/public/system/core.h"
9 #include "mojo/system/core_impl.h"
10
11 char* ReadStringFromPipe(mojo::Handle pipe) {
12 uint32_t len = 0;
13 char* buf = NULL;
14 MojoResult result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL,
15 MOJO_READ_MESSAGE_FLAG_NONE);
16 if (result == MOJO_RESULT_RESOURCE_EXHAUSTED) {
17 buf = new char[len];
18 result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL,
19 MOJO_READ_MESSAGE_FLAG_NONE);
20 }
21 if (result < MOJO_RESULT_OK) {
22 // Failure..
23 if (buf)
24 delete[] buf;
25 return NULL;
26 }
27 return buf;
28 }
29
30 class SampleMessageWaiter {
31 public:
32 explicit SampleMessageWaiter(mojo::Handle pipe) : pipe_(pipe) {}
33 ~SampleMessageWaiter() {}
34
35 void Read() {
36 char* string = ReadStringFromPipe(pipe_);
37 if (string) {
38 printf("Read string from pipe: %s\n", string);
39 delete[] string;
40 string = NULL;
41 }
42 }
43
44 void WaitAndRead() {
45 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100);
46 if (result < MOJO_RESULT_OK) {
47 // Failure...
48 }
49
50 Read();
51 }
52
53 private:
54
55 mojo::Handle pipe_;
56 DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter);
57 };
58
59 extern "C" __declspec(dllexport) MojoResult __cdecl MojoMain(
60 mojo::Handle pipe) {
61 SampleMessageWaiter(pipe).WaitAndRead();
62 return MOJO_RESULT_OK;
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698