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

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

Issue 11879042: Improve the error-propagation on socket streams (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 7 years, 11 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 | sdk/lib/io/http_parser.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 // The close queue handles graceful closing of HTTP connections. When 7 // The close queue handles graceful closing of HTTP connections. When
8 // a connection is added to the queue it will enter a wait state 8 // a connection is added to the queue it will enter a wait state
9 // waiting for all data written and possibly socket shutdown from 9 // waiting for all data written and possibly socket shutdown from
10 // peer. 10 // peer.
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // Register handlers for socket events. All socket events are 744 // Register handlers for socket events. All socket events are
745 // passed to the HTTP parser. 745 // passed to the HTTP parser.
746 _socket.onData = () { 746 _socket.onData = () {
747 List<int> buffer = _socket.read(); 747 List<int> buffer = _socket.read();
748 if (buffer != null) { 748 if (buffer != null) {
749 _httpParser.streamData(buffer); 749 _httpParser.streamData(buffer);
750 } 750 }
751 }; 751 };
752 _socket.onClosed = _httpParser.streamDone; 752 _socket.onClosed = _httpParser.streamDone;
753 _socket.onError = _httpParser.streamError; 753 _socket.onError = _httpParser.streamError;
754 // Ignore errors in the socket output stream as this is getting 754 _socket.outputStream.onError = _httpParser.streamError;
755 // the same errors as the socket itself.
756 _socket.outputStream.onError = (e) => null;
757 } 755 }
758 756
759 bool _write(List<int> data, [bool copyBuffer = false]); 757 bool _write(List<int> data, [bool copyBuffer = false]);
760 bool _writeFrom(List<int> buffer, [int offset, int len]); 758 bool _writeFrom(List<int> buffer, [int offset, int len]);
761 bool _flush(); 759 bool _flush();
762 bool _close(); 760 bool _close();
763 bool _destroy(); 761 bool _destroy();
764 DetachedSocket _detachSocket(); 762 DetachedSocket _detachSocket();
765 763
766 HttpConnectionInfo get connectionInfo { 764 HttpConnectionInfo get connectionInfo {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 _socket.onError = null; 867 _socket.onError = null;
870 _socket.outputStream.onNoPendingWrites = null; 868 _socket.outputStream.onNoPendingWrites = null;
871 _writeBufferedResponse(); 869 _writeBufferedResponse();
872 Socket socket = _socket; 870 Socket socket = _socket;
873 _socket = null; 871 _socket = null;
874 if (onDetach != null) onDetach(); 872 if (onDetach != null) onDetach();
875 return new _DetachedSocket(socket, _httpParser.readUnparsedData()); 873 return new _DetachedSocket(socket, _httpParser.readUnparsedData());
876 } 874 }
877 875
878 void _onError(e) { 876 void _onError(e) {
879 onError(e); 877 // Don't report errors for a request parser when HTTP parser is in
878 // idle state. Clients can close the connection and cause a
879 // connection reset by peer error which is OK.
880 _onClosed();
881 if (_state == _HttpConnectionBase.IDLE) return;
882
880 // Propagate the error to the streams. 883 // Propagate the error to the streams.
881 if (_request != null && _request._streamErrorHandler != null) { 884 if (_request != null &&
885 !_isRequestDone &&
886 _request._streamErrorHandler != null) {
882 _request._streamErrorHandler(e); 887 _request._streamErrorHandler(e);
883 } 888 } else if (_response != null &&
884 if (_response != null && _response._streamErrorHandler != null) { 889 !_isResponseDone &&
890 _response._streamErrorHandler != null) {
885 _response._streamErrorHandler(e); 891 _response._streamErrorHandler(e);
892 } else {
893 onError(e);
886 } 894 }
887 if (_socket != null) _socket.close(); 895 if (_socket != null) _socket.close();
888 } 896 }
889 897
890 void _onRequestReceived(String method, 898 void _onRequestReceived(String method,
891 String uri, 899 String uri,
892 String version, 900 String version,
893 _HttpHeaders headers, 901 _HttpHeaders headers,
894 bool hasBody) { 902 bool hasBody) {
895 _state = _HttpConnectionBase.ACTIVE; 903 _state = _HttpConnectionBase.ACTIVE;
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 2322
2315 2323
2316 class _RedirectInfo implements RedirectInfo { 2324 class _RedirectInfo implements RedirectInfo {
2317 const _RedirectInfo(int this.statusCode, 2325 const _RedirectInfo(int this.statusCode,
2318 String this.method, 2326 String this.method,
2319 Uri this.location); 2327 Uri this.location);
2320 final int statusCode; 2328 final int statusCode;
2321 final String method; 2329 final String method;
2322 final Uri location; 2330 final Uri location;
2323 } 2331 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/http_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698