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

Side by Side Diff: mojo/public/cpp/system/message_pipe.h

Issue 1785843002: [mojo] Implement pipe fusion API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 // This file provides a C++ wrapping around the Mojo C API for message pipes, 5 // This file provides a C++ wrapping around the Mojo C API for message pipes,
6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more 6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more
7 // strongly-typed representations of |MojoHandle|s. 7 // strongly-typed representations of |MojoHandle|s.
8 // 8 //
9 // Please see "mojo/public/c/system/message_pipe.h" for complete documentation 9 // Please see "mojo/public/c/system/message_pipe.h" for complete documentation
10 // of the API. 10 // of the API.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 inline MojoResult ReadMessageRaw(MessagePipeHandle message_pipe, 82 inline MojoResult ReadMessageRaw(MessagePipeHandle message_pipe,
83 void* bytes, 83 void* bytes,
84 uint32_t* num_bytes, 84 uint32_t* num_bytes,
85 MojoHandle* handles, 85 MojoHandle* handles,
86 uint32_t* num_handles, 86 uint32_t* num_handles,
87 MojoReadMessageFlags flags) { 87 MojoReadMessageFlags flags) {
88 return MojoReadMessage( 88 return MojoReadMessage(
89 message_pipe.value(), bytes, num_bytes, handles, num_handles, flags); 89 message_pipe.value(), bytes, num_bytes, handles, num_handles, flags);
90 } 90 }
91 91
92 // Fuses two message pipes together at the given handles. See
93 // |MojoFuseMessagePipes()| for complete documentation. Note that this may
94 // reset the passed handle arguments on success or unrecoverable failure.
95 inline MojoResult FuseMessagePipes(ScopedMessagePipeHandle *message_pipe0,
yzshen1 2016/03/10 23:49:03 nit: * should be adjacent to the type, instead of
Ken Rockot(use gerrit already) 2016/03/11 00:32:46 WontFix - obsolete :)
96 ScopedMessagePipeHandle *message_pipe1) {
97 MojoResult result = MojoFuseMessagePipes(message_pipe0->get().value(),
98 message_pipe1->get().value());
99 if (result == MOJO_RESULT_INVALID_ARGUMENT)
100 return result;
101
102 CHECK(result == MOJO_RESULT_FAILED_PRECONDITION || result == MOJO_RESULT_OK);
103
104 // The handles were closed internally.
105 (void)message_pipe0->release();
106 (void)message_pipe1->release();
107
108 return result;
109 }
110
92 // A wrapper class that automatically creates a message pipe and owns both 111 // A wrapper class that automatically creates a message pipe and owns both
93 // handles. 112 // handles.
94 class MessagePipe { 113 class MessagePipe {
95 public: 114 public:
96 MessagePipe(); 115 MessagePipe();
97 explicit MessagePipe(const MojoCreateMessagePipeOptions& options); 116 explicit MessagePipe(const MojoCreateMessagePipeOptions& options);
98 ~MessagePipe(); 117 ~MessagePipe();
99 118
100 ScopedMessagePipeHandle handle0; 119 ScopedMessagePipeHandle handle0;
101 ScopedMessagePipeHandle handle1; 120 ScopedMessagePipeHandle handle1;
102 }; 121 };
103 122
104 inline MessagePipe::MessagePipe() { 123 inline MessagePipe::MessagePipe() {
105 MojoResult result = CreateMessagePipe(nullptr, &handle0, &handle1); 124 MojoResult result = CreateMessagePipe(nullptr, &handle0, &handle1);
106 DCHECK_EQ(MOJO_RESULT_OK, result); 125 DCHECK_EQ(MOJO_RESULT_OK, result);
107 } 126 }
108 127
109 inline MessagePipe::MessagePipe(const MojoCreateMessagePipeOptions& options) { 128 inline MessagePipe::MessagePipe(const MojoCreateMessagePipeOptions& options) {
110 MojoResult result = CreateMessagePipe(&options, &handle0, &handle1); 129 MojoResult result = CreateMessagePipe(&options, &handle0, &handle1);
111 DCHECK_EQ(MOJO_RESULT_OK, result); 130 DCHECK_EQ(MOJO_RESULT_OK, result);
112 } 131 }
113 132
114 inline MessagePipe::~MessagePipe() { 133 inline MessagePipe::~MessagePipe() {
115 } 134 }
116 135
117 } // namespace mojo 136 } // namespace mojo
118 137
119 #endif // MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ 138 #endif // MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698