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

Side by Side Diff: sdk/lib/io/http_parser.dart

Issue 12385048: Support canceling an incoming message, while the other end will be notified (by write-error from th… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/io/http_close_test.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 (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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 return byte - 0x61 + 10; // a - f 867 return byte - 0x61 + 10; // a - f
868 } else { 868 } else {
869 throw new HttpParserException("Failed to parse HTTP"); 869 throw new HttpParserException("Failed to parse HTTP");
870 } 870 }
871 } 871 }
872 872
873 void _createIncoming(int transferLength) { 873 void _createIncoming(int transferLength) {
874 assert(_incoming == null); 874 assert(_incoming == null);
875 assert(_bodyController == null); 875 assert(_bodyController == null);
876 _bodyController = new StreamController<List<int>>( 876 _bodyController = new StreamController<List<int>>(
877 onSubscriptionStateChange: _updateParsePauseState, 877 onSubscriptionStateChange: _bodySubscriptionStateChange,
878 onPauseStateChange: _updateParsePauseState); 878 onPauseStateChange: _updateParsePauseState);
879 _incoming = new _HttpIncoming( 879 _incoming = new _HttpIncoming(
880 _headers, transferLength, _bodyController.stream); 880 _headers, transferLength, _bodyController.stream);
881 _pauseParsing(); // Needed to handle detaching - don't start on the body! 881 _pauseParsing(); // Needed to handle detaching - don't start on the body!
882 } 882 }
883 883
884 void _closeIncoming() { 884 void _closeIncoming() {
885 assert(_incoming != null); 885 assert(_incoming != null);
886 var tmp = _incoming; 886 var tmp = _incoming;
887 _incoming = null; 887 _incoming = null;
888 tmp.close(); 888 tmp.close();
889 if (_bodyController != null) { 889 if (_bodyController != null) {
890 _bodyController.close(); 890 _bodyController.close();
891 _bodyController = null; 891 _bodyController = null;
892 } 892 }
893 _updateParsePauseState(); 893 _updateParsePauseState();
894 } 894 }
895 895
896 void _continueParsing() { 896 void _continueParsing() {
897 _paused = false; 897 _paused = false;
898 if (!_parserCalled && _buffer != null) _parse(); 898 if (!_parserCalled && _buffer != null) _parse();
899 } 899 }
900 900
901 void _pauseParsing() { 901 void _pauseParsing() {
902 _paused = true; 902 _paused = true;
903 } 903 }
904 904
905 void _bodySubscriptionStateChange() {
906 if (_incoming != null && !_bodyController.hasSubscribers) {
907 _closeIncoming();
908 } else {
909 _updateParsePauseState();
910 }
911 }
912
905 void _updateParsePauseState() { 913 void _updateParsePauseState() {
906 if (_bodyController != null) { 914 if (_bodyController != null) {
907 if (_bodyController.hasSubscribers && !_bodyController.isPaused) { 915 if (_bodyController.hasSubscribers && !_bodyController.isPaused) {
908 _continueParsing(); 916 _continueParsing();
909 } else { 917 } else {
910 _pauseParsing(); 918 _pauseParsing();
911 } 919 }
912 } else { 920 } else {
913 if (_controller.hasSubscribers && !_controller.isPaused) { 921 if (_controller.hasSubscribers && !_controller.isPaused) {
914 _continueParsing(); 922 _continueParsing();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 StreamController<_HttpIncoming> _controller; 970 StreamController<_HttpIncoming> _controller;
963 StreamController<List<int>> _bodyController; 971 StreamController<List<int>> _bodyController;
964 } 972 }
965 973
966 974
967 class HttpParserException implements Exception { 975 class HttpParserException implements Exception {
968 const HttpParserException([String this.message = ""]); 976 const HttpParserException([String this.message = ""]);
969 String toString() => "HttpParserException: $message"; 977 String toString() => "HttpParserException: $message";
970 final String message; 978 final String message;
971 } 979 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_close_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698