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

Side by Side Diff: ipc/mojo/ipc_message_pipe_reader.cc

Issue 1023043002: ChannelMojo: Let MessagePipeReader wait "peer closed" signal as well. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "ipc/mojo/ipc_message_pipe_reader.h" 5 #include "ipc/mojo/ipc_message_pipe_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 void MessagePipeReader::ReadMessagesThenWait() { 155 void MessagePipeReader::ReadMessagesThenWait() {
156 while (true) { 156 while (true) {
157 ReadAvailableMessages(); 157 ReadAvailableMessages();
158 if (!pipe_.is_valid()) 158 if (!pipe_.is_valid())
159 break; 159 break;
160 // |Wait()| is safe to call only after all messages are read. 160 // |Wait()| is safe to call only after all messages are read.
161 // If can fail with |MOJO_RESULT_ALREADY_EXISTS| otherwise. 161 // If can fail with |MOJO_RESULT_ALREADY_EXISTS| otherwise.
162 // Also, we don't use MOJO_HANDLE_SIGNAL_WRITABLE here, expecting buffer in 162 // Also, we don't use MOJO_HANDLE_SIGNAL_WRITABLE here, expecting buffer in
163 // MessagePipe. 163 // MessagePipe.
164 MojoResult result = 164 MojoResult result = async_waiter_->Wait(
165 async_waiter_->Wait(pipe_.get().value(), MOJO_HANDLE_SIGNAL_READABLE); 165 pipe_.get().value(),
166 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED);
viettrungluu 2015/03/24 21:03:25 So if it gets signaled due to "peer closed" ... th
166 // If the result is |MOJO_RESULT_ALREADY_EXISTS|, there could be messages 167 // If the result is |MOJO_RESULT_ALREADY_EXISTS|, there could be messages
167 // that have been arrived after the last |ReadAvailableMessages()|. 168 // that have been arrived after the last |ReadAvailableMessages()|.
168 // We have to consume then and retry in that case. 169 // We have to consume then and retry in that case.
169 if (result != MOJO_RESULT_ALREADY_EXISTS) { 170 if (result != MOJO_RESULT_ALREADY_EXISTS) {
viettrungluu 2015/03/24 21:03:25 It seems to me that without adding "peer closed" a
170 if (result != MOJO_RESULT_OK) { 171 if (result != MOJO_RESULT_OK) {
viettrungluu 2015/03/24 21:03:25 And then end up down this path. Why doesn't this w
Hajime Morrita 2015/03/24 21:13:36 The issue isn't real crash. My understanding is th
171 LOG(ERROR) << "Failed to wait on the pipe. Result is " << result; 172 LOG(ERROR) << "Failed to wait on the pipe. Result is " << result;
172 OnPipeError(result); 173 OnPipeError(result);
173 Close(); 174 Close();
174 } 175 }
175 176
176 break; 177 break;
177 } 178 }
178 } 179 }
179 } 180 }
180 181
181 void MessagePipeReader::PipeIsReady(MojoResult wait_result) { 182 void MessagePipeReader::PipeIsReady(MojoResult wait_result) {
182 if (wait_result != MOJO_RESULT_OK) { 183 if (wait_result != MOJO_RESULT_OK) {
183 if (wait_result != MOJO_RESULT_ABORTED) { 184 if (wait_result != MOJO_RESULT_ABORTED) {
viettrungluu 2015/03/24 21:03:26 It seems unlikely to me that you should ever see M
Hajime Morrita 2015/03/24 21:13:36 This has been here from the beginning but is proba
184 // FAILED_PRECONDITION happens every time the peer is dead so 185 // FAILED_PRECONDITION happens every time the peer is dead so
viettrungluu 2015/03/24 21:03:25 And with your change, you shouldn't get "failed pr
Hajime Morrita 2015/03/24 21:13:36 Right. Removing.
185 // it isn't worth polluting the log message. 186 // it isn't worth polluting the log message.
186 LOG_IF(WARNING, wait_result != MOJO_RESULT_FAILED_PRECONDITION) 187 LOG_IF(WARNING, wait_result != MOJO_RESULT_FAILED_PRECONDITION)
187 << "Pipe got error from the waiter. Closing: " << wait_result; 188 << "Pipe got error from the waiter. Closing: " << wait_result;
188 OnPipeError(wait_result); 189 OnPipeError(wait_result);
189 } 190 }
190 191
191 Close(); 192 Close();
192 return; 193 return;
193 } 194 }
194 195
195 ReadMessagesThenWait(); 196 ReadMessagesThenWait();
196 } 197 }
197 198
198 void MessagePipeReader::DelayedDeleter::operator()( 199 void MessagePipeReader::DelayedDeleter::operator()(
199 MessagePipeReader* ptr) const { 200 MessagePipeReader* ptr) const {
200 ptr->Close(); 201 ptr->Close();
201 base::MessageLoopProxy::current()->PostTask( 202 base::MessageLoopProxy::current()->PostTask(
202 FROM_HERE, base::Bind(&DeleteNow, ptr)); 203 FROM_HERE, base::Bind(&DeleteNow, ptr));
203 } 204 }
204 205
205 } // namespace internal 206 } // namespace internal
206 } // namespace IPC 207 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698