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

Side by Side Diff: mojo/public/dart/src/event_stream.dart

Issue 987523002: Dart: Fixes bug in MojoEventStreamListener (Closed) Base URL: git@github.com:domokit/mojo.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 | services/dart/dart_apptests/echo_apptests.dart » ('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 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 part of core; 5 part of core;
6 6
7 class MojoEventStream extends Stream<List<int>> { 7 class MojoEventStream extends Stream<List<int>> {
8 // The underlying Mojo handle. 8 // The underlying Mojo handle.
9 MojoHandle _handle; 9 MojoHandle _handle;
10 10
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 _eventStream = new MojoEventStream(handle); 172 _eventStream = new MojoEventStream(handle);
173 _isOpen = false; 173 _isOpen = false;
174 } 174 }
175 175
176 StreamSubscription<List<int>> listen({Function onClosed}) { 176 StreamSubscription<List<int>> listen({Function onClosed}) {
177 assert(isBound && (subscription == null)); 177 assert(isBound && (subscription == null));
178 _isOpen = true; 178 _isOpen = true;
179 subscription = _eventStream.listen((List<int> event) { 179 subscription = _eventStream.listen((List<int> event) {
180 var signalsWatched = new MojoHandleSignals(event[0]); 180 var signalsWatched = new MojoHandleSignals(event[0]);
181 var signalsReceived = new MojoHandleSignals(event[1]); 181 var signalsReceived = new MojoHandleSignals(event[1]);
182 if (signalsReceived.isPeerClosed) {
183 if (onClosed != null) onClosed();
184 close();
185 // The peer being closed obviates any other signal we might
186 // have received since we won't be able to read or write the handle.
187 // Thus, we just return before invoking other handlers.
188 return;
189 }
190 _isInHandler = true; 182 _isInHandler = true;
191 if (signalsReceived.isReadable) { 183 if (signalsReceived.isReadable) {
192 assert(_eventStream.readyRead); 184 assert(_eventStream.readyRead);
193 handleRead(); 185 handleRead();
194 } 186 }
195 if (signalsReceived.isWritable) { 187 if (signalsReceived.isWritable) {
196 assert(_eventStream.readyWrite); 188 assert(_eventStream.readyWrite);
197 handleWrite(); 189 handleWrite();
198 } 190 }
199 if (_isOpen) { 191 if (_isOpen) {
200 _eventStream.enableSignals(signalsWatched); 192 _eventStream.enableSignals(signalsWatched);
201 } 193 }
202 _isInHandler = false; 194 _isInHandler = false;
195 if (signalsReceived.isPeerClosed) {
196 if (onClosed != null) onClosed();
197 close();
198 // The peer being closed obviates any other signal we might
199 // have received since we won't be able to read or write the handle.
200 // Thus, we just return before invoking other handlers.
201 return;
202 }
203 }, onDone: close); 203 }, onDone: close);
204 return subscription; 204 return subscription;
205 } 205 }
206 206
207 void close() { 207 void close() {
208 _isOpen = false; 208 _isOpen = false;
209 _endpoint = null; 209 _endpoint = null;
210 subscription = null; 210 subscription = null;
211 if (_eventStream != null) { 211 if (_eventStream != null) {
212 _eventStream.close(); 212 _eventStream.close();
213 _eventStream = null; 213 _eventStream = null;
214 } 214 }
215 } 215 }
216 216
217 void handleRead() {} 217 void handleRead() {}
218 void handleWrite() {} 218 void handleWrite() {}
219 219
220 MojoMessagePipeEndpoint get endpoint => _endpoint; 220 MojoMessagePipeEndpoint get endpoint => _endpoint;
221 bool get isOpen => _isOpen; 221 bool get isOpen => _isOpen;
222 bool get isInHandler => _isInHandler; 222 bool get isInHandler => _isInHandler;
223 bool get isBound => _endpoint != null; 223 bool get isBound => _endpoint != null;
224 } 224 }
OLDNEW
« no previous file with comments | « no previous file | services/dart/dart_apptests/echo_apptests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698