OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 // Global constants. | 7 // Global constants. |
8 class _Const { | 8 class _Const { |
9 // Bytes for "HTTP". | 9 // Bytes for "HTTP". |
10 static const HTTP = const [72, 84, 84, 80]; | 10 static const HTTP = const [72, 84, 84, 80]; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 | 280 |
281 factory _HttpParser.responseParser() { | 281 factory _HttpParser.responseParser() { |
282 return new _HttpParser._(false); | 282 return new _HttpParser._(false); |
283 } | 283 } |
284 | 284 |
285 _HttpParser._(this._requestParser) { | 285 _HttpParser._(this._requestParser) { |
286 _controller = new StreamController<_HttpIncoming>( | 286 _controller = new StreamController<_HttpIncoming>( |
287 sync: true, | 287 sync: true, |
288 onListen: () { | 288 onListen: () { |
289 _socketSubscription.resume(); | |
290 _paused = false; | 289 _paused = false; |
291 }, | 290 }, |
292 onPause: () { | 291 onPause: () { |
293 _paused = true; | 292 _paused = true; |
294 _pauseStateChanged(); | 293 _pauseStateChanged(); |
295 }, | 294 }, |
296 onResume: () { | 295 onResume: () { |
297 _paused = false; | 296 _paused = false; |
298 _pauseStateChanged(); | 297 _pauseStateChanged(); |
299 }, | 298 }, |
(...skipping 22 matching lines...) Expand all Loading... |
322 // given to provide a way of controlling the parser. | 321 // given to provide a way of controlling the parser. |
323 // TODO(ajohnsen): Remove _dataPause, _dataResume and _dataDone and clean up | 322 // TODO(ajohnsen): Remove _dataPause, _dataResume and _dataDone and clean up |
324 // how the _HttpIncoming signals the parser. | 323 // how the _HttpIncoming signals the parser. |
325 var completer = new Completer(); | 324 var completer = new Completer(); |
326 _socketSubscription = stream.listen( | 325 _socketSubscription = stream.listen( |
327 _onData, | 326 _onData, |
328 onError: _onError, | 327 onError: _onError, |
329 onDone: () { | 328 onDone: () { |
330 completer.complete(this); | 329 completer.complete(this); |
331 }); | 330 }); |
332 _socketSubscription.pause(); | |
333 return completer.future; | 331 return completer.future; |
334 } | 332 } |
335 | 333 |
336 Future<_HttpParser> close() { | 334 Future<_HttpParser> close() { |
337 _onDone(); | 335 _onDone(); |
338 return new Future.value(this); | 336 return new Future.value(this); |
339 } | 337 } |
340 | 338 |
341 void _parse() { | 339 void _parse() { |
342 try { | 340 try { |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 } | 1036 } |
1039 } | 1037 } |
1040 | 1038 |
1041 void _reportError(error, [stackTrace]) { | 1039 void _reportError(error, [stackTrace]) { |
1042 if (_socketSubscription != null) _socketSubscription.cancel(); | 1040 if (_socketSubscription != null) _socketSubscription.cancel(); |
1043 _state = _State.FAILURE; | 1041 _state = _State.FAILURE; |
1044 _controller.addError(error, stackTrace); | 1042 _controller.addError(error, stackTrace); |
1045 _controller.close(); | 1043 _controller.close(); |
1046 } | 1044 } |
1047 } | 1045 } |
OLD | NEW |