OLD | NEW |
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 Loading... |
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); |
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) { |
170 if (result != MOJO_RESULT_OK) { | 171 if (result != MOJO_RESULT_OK) { |
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 CHECK_NE(wait_result, MOJO_RESULT_ABORTED); |
184 // FAILED_PRECONDITION happens every time the peer is dead so | 185 LOG(ERROR) << "Pipe got error from the waiter. Closing: " << wait_result; |
185 // it isn't worth polluting the log message. | 186 OnPipeError(wait_result); |
186 LOG_IF(WARNING, wait_result != MOJO_RESULT_FAILED_PRECONDITION) | |
187 << "Pipe got error from the waiter. Closing: " << wait_result; | |
188 OnPipeError(wait_result); | |
189 } | |
190 | 187 |
191 Close(); | 188 Close(); |
192 return; | 189 return; |
193 } | 190 } |
194 | 191 |
195 ReadMessagesThenWait(); | 192 ReadMessagesThenWait(); |
196 } | 193 } |
197 | 194 |
198 void MessagePipeReader::DelayedDeleter::operator()( | 195 void MessagePipeReader::DelayedDeleter::operator()( |
199 MessagePipeReader* ptr) const { | 196 MessagePipeReader* ptr) const { |
200 ptr->Close(); | 197 ptr->Close(); |
201 base::MessageLoopProxy::current()->PostTask( | 198 base::MessageLoopProxy::current()->PostTask( |
202 FROM_HERE, base::Bind(&DeleteNow, ptr)); | 199 FROM_HERE, base::Bind(&DeleteNow, ptr)); |
203 } | 200 } |
204 | 201 |
205 } // namespace internal | 202 } // namespace internal |
206 } // namespace IPC | 203 } // namespace IPC |
OLD | NEW |