| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool _isCanceled = false; | 114 bool _isCanceled = false; |
| 115 int _pauseCount = 1; | 115 int _pauseCount = 1; |
| 116 Function _userOnData; | 116 Function _userOnData; |
| 117 bool _scheduled = false; | 117 bool _scheduled = false; |
| 118 | 118 |
| 119 _HttpDetachedStreamSubscription( | 119 _HttpDetachedStreamSubscription( |
| 120 this._subscription, this._injectData, this._userOnData); | 120 this._subscription, this._injectData, this._userOnData); |
| 121 | 121 |
| 122 bool get isPaused => _subscription.isPaused; | 122 bool get isPaused => _subscription.isPaused; |
| 123 | 123 |
| 124 Future<T> | 124 Future<T> asFuture<T>([T futureValue]) => |
| 125 asFuture<T>([T futureValue]) => _subscription.asFuture<T>(futureValue); | 125 _subscription.asFuture<T>(futureValue); |
| 126 | 126 |
| 127 Future cancel() { | 127 Future cancel() { |
| 128 _isCanceled = true; | 128 _isCanceled = true; |
| 129 _injectData = null; | 129 _injectData = null; |
| 130 return _subscription.cancel(); | 130 return _subscription.cancel(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void onData(void handleData(List<int> data)) { | 133 void onData(void handleData(List<int> data)) { |
| 134 _userOnData = handleData; | 134 _userOnData = handleData; |
| 135 _subscription.onData(handleData); | 135 _subscription.onData(handleData); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 {Function onError, void onDone(), bool cancelOnError}) { | 192 {Function onError, void onDone(), bool cancelOnError}) { |
| 193 if (subscription != null) { | 193 if (subscription != null) { |
| 194 subscription | 194 subscription |
| 195 ..onData(onData) | 195 ..onData(onData) |
| 196 ..onError(onError) | 196 ..onError(onError) |
| 197 ..onDone(onDone); | 197 ..onDone(onDone); |
| 198 if (bufferedData == null) { | 198 if (bufferedData == null) { |
| 199 return subscription..resume(); | 199 return subscription..resume(); |
| 200 } | 200 } |
| 201 return new _HttpDetachedStreamSubscription( | 201 return new _HttpDetachedStreamSubscription( |
| 202 subscription, bufferedData, onData)..resume(); | 202 subscription, bufferedData, onData) |
| 203 ..resume(); |
| 203 } else { | 204 } else { |
| 204 // TODO(26379): add test for this branch. | 205 // TODO(26379): add test for this branch. |
| 205 return new Stream<List<int>>.fromIterable([bufferedData]).listen(onData, | 206 return new Stream<List<int>>.fromIterable([bufferedData]).listen(onData, |
| 206 onError: onError, onDone: onDone, cancelOnError: cancelOnError); | 207 onError: onError, onDone: onDone, cancelOnError: cancelOnError); |
| 207 } | 208 } |
| 208 } | 209 } |
| 209 } | 210 } |
| 210 | 211 |
| 211 /** | 212 /** |
| 212 * HTTP parser which parses the data stream given to [consume]. | 213 * HTTP parser which parses the data stream given to [consume]. |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 } | 1047 } |
| 1047 } | 1048 } |
| 1048 | 1049 |
| 1049 void _reportError(error, [stackTrace]) { | 1050 void _reportError(error, [stackTrace]) { |
| 1050 if (_socketSubscription != null) _socketSubscription.cancel(); | 1051 if (_socketSubscription != null) _socketSubscription.cancel(); |
| 1051 _state = _State.FAILURE; | 1052 _state = _State.FAILURE; |
| 1052 _controller.addError(error, stackTrace); | 1053 _controller.addError(error, stackTrace); |
| 1053 _controller.close(); | 1054 _controller.close(); |
| 1054 } | 1055 } |
| 1055 } | 1056 } |
| OLD | NEW |