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

Side by Side Diff: mojo/public/cpp/bindings/lib/connector.cc

Issue 409943003: Makes HandleWatcher block until no longer waiting on pipe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more java fixes Created 6 years, 5 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 | Annotate | Revision Log
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/public/cpp/bindings/lib/connector.h" 5 #include "mojo/public/cpp/bindings/lib/connector.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "mojo/public/cpp/bindings/error_handler.h" 9 #include "mojo/public/cpp/bindings/error_handler.h"
10 #include "mojo/public/cpp/environment/logging.h" 10 #include "mojo/public/cpp/environment/logging.h"
(...skipping 16 matching lines...) Expand all
27 destroyed_flag_(NULL) { 27 destroyed_flag_(NULL) {
28 // Even though we don't have an incoming receiver, we still want to monitor 28 // Even though we don't have an incoming receiver, we still want to monitor
29 // the message pipe to know if is closed or encounters an error. 29 // the message pipe to know if is closed or encounters an error.
30 WaitToReadMore(); 30 WaitToReadMore();
31 } 31 }
32 32
33 Connector::~Connector() { 33 Connector::~Connector() {
34 if (destroyed_flag_) 34 if (destroyed_flag_)
35 *destroyed_flag_ = true; 35 *destroyed_flag_ = true;
36 36
37 if (async_wait_id_) 37 CancelWait();
38 waiter_->CancelWait(async_wait_id_);
39 } 38 }
40 39
41 void Connector::CloseMessagePipe() { 40 void Connector::CloseMessagePipe() {
41 CancelWait();
42 Close(message_pipe_.Pass()); 42 Close(message_pipe_.Pass());
43 } 43 }
44 44
45 ScopedMessagePipeHandle Connector::PassMessagePipe() { 45 ScopedMessagePipeHandle Connector::PassMessagePipe() {
46 if (async_wait_id_) { 46 CancelWait();
47 waiter_->CancelWait(async_wait_id_);
48 async_wait_id_ = 0;
49 }
50 return message_pipe_.Pass(); 47 return message_pipe_.Pass();
51 } 48 }
52 49
53 bool Connector::WaitForIncomingMessage() { 50 bool Connector::WaitForIncomingMessage() {
54 if (error_) 51 if (error_)
55 return false; 52 return false;
56 53
57 MojoResult rv = Wait(message_pipe_.get(), 54 MojoResult rv = Wait(message_pipe_.get(),
58 MOJO_HANDLE_SIGNAL_READABLE, 55 MOJO_HANDLE_SIGNAL_READABLE,
59 MOJO_DEADLINE_INDEFINITE); 56 MOJO_DEADLINE_INDEFINITE);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 async_wait_id_ = 0; 126 async_wait_id_ = 0;
130 if (result != MOJO_RESULT_OK) { 127 if (result != MOJO_RESULT_OK) {
131 NotifyError(); 128 NotifyError();
132 return; 129 return;
133 } 130 }
134 ReadAllAvailableMessages(); 131 ReadAllAvailableMessages();
135 // At this point, this object might have been deleted. Return. 132 // At this point, this object might have been deleted. Return.
136 } 133 }
137 134
138 void Connector::WaitToReadMore() { 135 void Connector::WaitToReadMore() {
136 MOJO_DCHECK(!async_wait_id_);
139 async_wait_id_ = waiter_->AsyncWait(message_pipe_.get().value(), 137 async_wait_id_ = waiter_->AsyncWait(message_pipe_.get().value(),
140 MOJO_HANDLE_SIGNAL_READABLE, 138 MOJO_HANDLE_SIGNAL_READABLE,
141 MOJO_DEADLINE_INDEFINITE, 139 MOJO_DEADLINE_INDEFINITE,
142 &Connector::CallOnHandleReady, 140 &Connector::CallOnHandleReady,
143 this); 141 this);
144 } 142 }
145 143
146 bool Connector::ReadSingleMessage(MojoResult* read_result) { 144 bool Connector::ReadSingleMessage(MojoResult* read_result) {
147 bool receiver_result = false; 145 bool receiver_result = false;
148 146
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if (!ReadSingleMessage(&rv)) 181 if (!ReadSingleMessage(&rv))
184 return; 182 return;
185 183
186 if (rv == MOJO_RESULT_SHOULD_WAIT) { 184 if (rv == MOJO_RESULT_SHOULD_WAIT) {
187 WaitToReadMore(); 185 WaitToReadMore();
188 break; 186 break;
189 } 187 }
190 } 188 }
191 } 189 }
192 190
191 void Connector::CancelWait() {
192 if (!async_wait_id_)
193 return;
194
195 waiter_->CancelWait(async_wait_id_);
196 async_wait_id_ = 0;
197 }
198
193 void Connector::NotifyError() { 199 void Connector::NotifyError() {
194 error_ = true; 200 error_ = true;
195 // The error handler might destroyed |this|. Also, after an error, all method 201 // The error handler might destroyed |this|. Also, after an error, all method
196 // should end early. 202 // should end early.
197 if (destroyed_flag_) { 203 if (destroyed_flag_) {
198 *destroyed_flag_ = true; // Propagate flag. 204 *destroyed_flag_ = true; // Propagate flag.
199 } 205 }
200 if (error_handler_) 206 if (error_handler_)
201 error_handler_->OnConnectionError(); 207 error_handler_->OnConnectionError();
202 } 208 }
203 209
204 } // namespace internal 210 } // namespace internal
205 } // namespace mojo 211 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698