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

Side by Side Diff: mojo/edk/system/core.cc

Issue 1488853002: Add multiplexing of message pipes in the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tsepez review comments Created 5 years 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
« no previous file with comments | « mojo/edk/system/child_broker_host.cc ('k') | mojo/edk/system/core_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/edk/system/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "mojo/edk/embedder/embedder_internal.h" 12 #include "mojo/edk/embedder/embedder_internal.h"
12 #include "mojo/edk/embedder/platform_channel_pair.h" 13 #include "mojo/edk/embedder/platform_channel_pair.h"
13 #include "mojo/edk/embedder/platform_shared_buffer.h" 14 #include "mojo/edk/embedder/platform_shared_buffer.h"
14 #include "mojo/edk/embedder/platform_support.h" 15 #include "mojo/edk/embedder/platform_support.h"
15 #include "mojo/edk/system/async_waiter.h" 16 #include "mojo/edk/system/async_waiter.h"
16 #include "mojo/edk/system/broker.h" 17 #include "mojo/edk/system/broker.h"
17 #include "mojo/edk/system/configuration.h" 18 #include "mojo/edk/system/configuration.h"
18 #include "mojo/edk/system/data_pipe.h" 19 #include "mojo/edk/system/data_pipe.h"
19 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" 20 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 handle_pair = handle_table_.AddDispatcherPair(dispatcher0, dispatcher1); 200 handle_pair = handle_table_.AddDispatcherPair(dispatcher0, dispatcher1);
200 } 201 }
201 if (handle_pair.first == MOJO_HANDLE_INVALID) { 202 if (handle_pair.first == MOJO_HANDLE_INVALID) {
202 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); 203 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID);
203 LOG(ERROR) << "Handle table full"; 204 LOG(ERROR) << "Handle table full";
204 dispatcher0->Close(); 205 dispatcher0->Close();
205 dispatcher1->Close(); 206 dispatcher1->Close();
206 return MOJO_RESULT_RESOURCE_EXHAUSTED; 207 return MOJO_RESULT_RESOURCE_EXHAUSTED;
207 } 208 }
208 209
209 ScopedPlatformHandle server_handle, client_handle; 210 if (validated_options.flags &
211 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE) {
212 ScopedPlatformHandle server_handle, client_handle;
210 #if defined(OS_WIN) 213 #if defined(OS_WIN)
211 internal::g_broker->CreatePlatformChannelPair(&server_handle, &client_handle); 214 internal::g_broker->CreatePlatformChannelPair(&server_handle,
215 &client_handle);
212 #else 216 #else
213 PlatformChannelPair channel_pair; 217 PlatformChannelPair channel_pair;
214 server_handle = channel_pair.PassServerHandle(); 218 server_handle = channel_pair.PassServerHandle();
215 client_handle = channel_pair.PassClientHandle(); 219 client_handle = channel_pair.PassClientHandle();
216 #endif 220 #endif
217 dispatcher0->Init(server_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr, 221 dispatcher0->Init(server_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr,
218 nullptr); 222 nullptr);
219 dispatcher1->Init(client_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr, 223 dispatcher1->Init(client_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr,
220 nullptr); 224 nullptr);
225 } else {
226 uint64_t pipe_id = 0;
227 while (pipe_id == 0)
228 pipe_id = base::RandUint64();
229 dispatcher0->InitNonTransferable(pipe_id);
230 dispatcher1->InitNonTransferable(pipe_id);
231 }
221 232
222 *message_pipe_handle0 = handle_pair.first; 233 *message_pipe_handle0 = handle_pair.first;
223 *message_pipe_handle1 = handle_pair.second; 234 *message_pipe_handle1 = handle_pair.second;
224 return MOJO_RESULT_OK; 235 return MOJO_RESULT_OK;
225 } 236 }
226 237
227 // Implementation note: To properly cancel waiters and avoid other races, this 238 // Implementation note: To properly cancel waiters and avoid other races, this
228 // does not transfer dispatchers from one handle to another, even when sending a 239 // does not transfer dispatchers from one handle to another, even when sending a
229 // message in-process. Instead, it must transfer the "contents" of the 240 // message in-process. Instead, it must transfer the "contents" of the
230 // dispatcher to a new dispatcher, and then close the old dispatcher. If this 241 // dispatcher to a new dispatcher, and then close the old dispatcher. If this
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (signals_states) { 617 if (signals_states) {
607 for (; i < num_handles; i++) 618 for (; i < num_handles; i++)
608 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); 619 signals_states[i] = dispatchers[i]->GetHandleSignalsState();
609 } 620 }
610 621
611 return rv; 622 return rv;
612 } 623 }
613 624
614 } // namespace edk 625 } // namespace edk
615 } // namespace mojo 626 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/child_broker_host.cc ('k') | mojo/edk/system/core_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698