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

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

Issue 1959523002: EDK: Plumb Handle/HandleVector one more layer down. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « mojo/edk/system/local_message_pipe_endpoint.h ('k') | mojo/edk/system/message_pipe.cc » ('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/local_message_pipe_endpoint.h" 5 #include "mojo/edk/system/local_message_pipe_endpoint.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void LocalMessagePipeEndpoint::CancelAllAwakables() { 65 void LocalMessagePipeEndpoint::CancelAllAwakables() {
66 DCHECK(is_open_); 66 DCHECK(is_open_);
67 awakable_list_.CancelAll(); 67 awakable_list_.CancelAll();
68 } 68 }
69 69
70 MojoResult LocalMessagePipeEndpoint::ReadMessage( 70 MojoResult LocalMessagePipeEndpoint::ReadMessage(
71 UserPointer<void> bytes, 71 UserPointer<void> bytes,
72 UserPointer<uint32_t> num_bytes, 72 UserPointer<uint32_t> num_bytes,
73 DispatcherVector* dispatchers, 73 HandleVector* handles,
74 uint32_t* num_dispatchers, 74 uint32_t* num_handles,
75 MojoReadMessageFlags flags) { 75 MojoReadMessageFlags flags) {
76 DCHECK(is_open_); 76 DCHECK(is_open_);
77 DCHECK(!dispatchers || dispatchers->empty()); 77 DCHECK(!handles || handles->empty());
78 78
79 const uint32_t max_bytes = num_bytes.IsNull() ? 0 : num_bytes.Get(); 79 const uint32_t max_bytes = num_bytes.IsNull() ? 0 : num_bytes.Get();
80 const uint32_t max_num_dispatchers = num_dispatchers ? *num_dispatchers : 0; 80 const uint32_t max_num_handles = num_handles ? *num_handles : 0;
81 81
82 if (message_queue_.IsEmpty()) { 82 if (message_queue_.IsEmpty()) {
83 return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT 83 return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT
84 : MOJO_RESULT_FAILED_PRECONDITION; 84 : MOJO_RESULT_FAILED_PRECONDITION;
85 } 85 }
86 86
87 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop 87 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop
88 // and release the lock immediately. 88 // and release the lock immediately.
89 bool enough_space = true; 89 bool enough_space = true;
90 MessageInTransit* message = message_queue_.PeekMessage(); 90 MessageInTransit* message = message_queue_.PeekMessage();
91 if (!num_bytes.IsNull()) 91 if (!num_bytes.IsNull())
92 num_bytes.Put(message->num_bytes()); 92 num_bytes.Put(message->num_bytes());
93 if (message->num_bytes() <= max_bytes) 93 if (message->num_bytes() <= max_bytes)
94 bytes.PutArray(message->bytes(), message->num_bytes()); 94 bytes.PutArray(message->bytes(), message->num_bytes());
95 else 95 else
96 enough_space = false; 96 enough_space = false;
97 97
98 if (DispatcherVector* queued_dispatchers = message->dispatchers()) { 98 if (DispatcherVector* queued_dispatchers = message->dispatchers()) {
99 if (num_dispatchers) 99 if (num_handles)
100 *num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size()); 100 *num_handles = static_cast<uint32_t>(queued_dispatchers->size());
101 if (enough_space) { 101 if (enough_space) {
102 if (queued_dispatchers->empty()) { 102 if (queued_dispatchers->empty()) {
103 // Nothing to do. 103 // Nothing to do.
104 } else if (queued_dispatchers->size() <= max_num_dispatchers) { 104 } else if (queued_dispatchers->size() <= max_num_handles) {
105 DCHECK(dispatchers); 105 DCHECK(handles);
106 dispatchers->swap(*queued_dispatchers); 106 // TODO(vtl): The rest of this code in this block is temporary, until I
107 // plumb |Handle|s into |MessageInTransit|. This should really just be
108 // something like:
109 // handles->swap(*queued_handles);
110 handles->reserve(queued_dispatchers->size());
111 for (size_t i = 0; i < queued_dispatchers->size(); i++) {
112 // We're not enforcing handle rights yet, so "none" is OK.
113 handles->push_back(Handle(std::move(queued_dispatchers->at(i)),
114 MOJO_HANDLE_RIGHT_NONE));
115 }
107 } else { 116 } else {
108 enough_space = false; 117 enough_space = false;
109 } 118 }
110 } 119 }
111 } else { 120 } else {
112 if (num_dispatchers) 121 if (num_handles)
113 *num_dispatchers = 0; 122 *num_handles = 0;
114 } 123 }
115 124
116 message = nullptr; 125 message = nullptr;
117 126
118 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { 127 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) {
119 message_queue_.DiscardMessage(); 128 message_queue_.DiscardMessage();
120 129
121 // Now it's empty, thus no longer readable. 130 // Now it's empty, thus no longer readable.
122 if (message_queue_.IsEmpty()) { 131 if (message_queue_.IsEmpty()) {
123 // It's currently not possible to wait for non-readability, but we should 132 // It's currently not possible to wait for non-readability, but we should
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 Awakable* awakable, 185 Awakable* awakable,
177 HandleSignalsState* signals_state) { 186 HandleSignalsState* signals_state) {
178 DCHECK(is_open_); 187 DCHECK(is_open_);
179 awakable_list_.Remove(awakable); 188 awakable_list_.Remove(awakable);
180 if (signals_state) 189 if (signals_state)
181 *signals_state = GetHandleSignalsState(); 190 *signals_state = GetHandleSignalsState();
182 } 191 }
183 192
184 } // namespace system 193 } // namespace system
185 } // namespace mojo 194 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/local_message_pipe_endpoint.h ('k') | mojo/edk/system/message_pipe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698