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

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

Issue 59673006: Use typed-data views for incoming http data. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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_parser_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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 case _State.BODY: 657 case _State.BODY:
658 // The body is not handled one byte at a time but in blocks. 658 // The body is not handled one byte at a time but in blocks.
659 _index--; 659 _index--;
660 int dataAvailable = _buffer.length - _index; 660 int dataAvailable = _buffer.length - _index;
661 List<int> data; 661 List<int> data;
662 if (_remainingContent == -1 || 662 if (_remainingContent == -1 ||
663 dataAvailable <= _remainingContent) { 663 dataAvailable <= _remainingContent) {
664 if (_index == 0) { 664 if (_index == 0) {
665 data = _buffer; 665 data = _buffer;
666 } else { 666 } else {
667 data = new Uint8List(dataAvailable); 667 data = new Uint8List.view(_buffer.buffer,
668 data.setRange(0, dataAvailable, _buffer, _index); 668 _index,
669 dataAvailable);
669 } 670 }
670 } else { 671 } else {
671 data = new Uint8List(_remainingContent); 672 data = new Uint8List.view(_buffer.buffer,
672 data.setRange(0, _remainingContent, _buffer, _index); 673 _index,
674 _remainingContent);
673 } 675 }
674 _bodyController.add(data); 676 _bodyController.add(data);
675 if (_remainingContent != -1) { 677 if (_remainingContent != -1) {
676 _remainingContent -= data.length; 678 _remainingContent -= data.length;
677 } 679 }
678 _index += data.length; 680 _index += data.length;
679 if (_remainingContent == 0) { 681 if (_remainingContent == 0) {
680 if (!_chunked) { 682 if (!_chunked) {
681 _reset(); 683 _reset();
682 _closeIncoming(); 684 _closeIncoming();
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 if (_socketSubscription != null) _socketSubscription.cancel(); 950 if (_socketSubscription != null) _socketSubscription.cancel();
949 _state = _State.FAILURE; 951 _state = _State.FAILURE;
950 _controller.addError(error, stackTrace); 952 _controller.addError(error, stackTrace);
951 _controller.close(); 953 _controller.close();
952 } 954 }
953 955
954 // State. 956 // State.
955 bool _parserCalled = false; 957 bool _parserCalled = false;
956 958
957 // The data that is currently being parsed. 959 // The data that is currently being parsed.
958 List<int> _buffer; 960 Uint8List _buffer;
959 int _index; 961 int _index;
960 962
961 final bool _requestParser; 963 final bool _requestParser;
962 int _state; 964 int _state;
963 int _httpVersionIndex; 965 int _httpVersionIndex;
964 int _messageType; 966 int _messageType;
965 int _statusCode = 0; 967 int _statusCode = 0;
966 List _method_or_status_code; 968 List _method_or_status_code;
967 List _uri_or_reason_phrase; 969 List _uri_or_reason_phrase;
968 List _headerField; 970 List _headerField;
(...skipping 12 matching lines...) Expand all
981 _HttpHeaders _headers; 983 _HttpHeaders _headers;
982 984
983 // The current incoming connection. 985 // The current incoming connection.
984 _HttpIncoming _incoming; 986 _HttpIncoming _incoming;
985 StreamSubscription _socketSubscription; 987 StreamSubscription _socketSubscription;
986 bool _paused = true; 988 bool _paused = true;
987 bool _bodyPaused = false; 989 bool _bodyPaused = false;
988 StreamController<_HttpIncoming> _controller; 990 StreamController<_HttpIncoming> _controller;
989 StreamController<List<int>> _bodyController; 991 StreamController<List<int>> _bodyController;
990 } 992 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698