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

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

Issue 1234163002: Fix a WebSocket crash. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 5 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
« no previous file with comments | « CHANGELOG.md ('k') | tests/standalone/io/web_socket_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 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
8 8
9 // Matches _WebSocketOpcode. 9 // Matches _WebSocketOpcode.
10 class _WebSocketMessageType { 10 class _WebSocketMessageType {
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 } 896 }
897 // Protocol close, use close code from transformer. 897 // Protocol close, use close code from transformer.
898 _closeCode = transformer.closeCode; 898 _closeCode = transformer.closeCode;
899 _closeReason = transformer.closeReason; 899 _closeReason = transformer.closeReason;
900 _controller.close(); 900 _controller.close();
901 }, 901 },
902 cancelOnError: true); 902 cancelOnError: true);
903 _subscription.pause(); 903 _subscription.pause();
904 _controller = new StreamController(sync: true, 904 _controller = new StreamController(sync: true,
905 onListen: _subscription.resume, 905 onListen: _subscription.resume,
906 onCancel: () {
907 _subscription.cancel();
908 _subscription = null;
909 },
906 onPause: _subscription.pause, 910 onPause: _subscription.pause,
907 onResume: _subscription.resume); 911 onResume: _subscription.resume);
908 912
909 _webSockets[_serviceId] = this; 913 _webSockets[_serviceId] = this;
910 try { _socket._owner = this; } catch (_) {} 914 try { _socket._owner = this; } catch (_) {}
911 } 915 }
912 916
913 StreamSubscription listen(void onData(message), 917 StreamSubscription listen(void onData(message),
914 {Function onError, 918 {Function onError,
915 void onDone(), 919 void onDone(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 if (_outCloseCode == null) { 962 if (_outCloseCode == null) {
959 _outCloseCode = code; 963 _outCloseCode = code;
960 _outCloseReason = reason; 964 _outCloseReason = reason;
961 } 965 }
962 if (!_controller.isClosed) { 966 if (!_controller.isClosed) {
963 // If a close has not yet been received from the other end then 967 // If a close has not yet been received from the other end then
964 // 1) make sure to listen on the stream so the close frame will be 968 // 1) make sure to listen on the stream so the close frame will be
965 // processed if received. 969 // processed if received.
966 // 2) set a timer terminate the connection if a close frame is 970 // 2) set a timer terminate the connection if a close frame is
967 // not received. 971 // not received.
968 if (!_controller.hasListener) { 972 if (!_controller.hasListener && _subscription != null) {
969 _controller.stream.drain().catchError((_) => {}); 973 _controller.stream.drain().catchError((_) => {});
970 } 974 }
971 if (_closeTimer == null) { 975 if (_closeTimer == null) {
972 // When closing the web-socket, we no longer accept data. 976 // When closing the web-socket, we no longer accept data.
973 _closeTimer = new Timer(const Duration(seconds: 5), () { 977 _closeTimer = new Timer(const Duration(seconds: 5), () {
974 // Reuse code and reason from the local close. 978 // Reuse code and reason from the local close.
975 _closeCode = _outCloseCode; 979 _closeCode = _outCloseCode;
976 _closeReason = _outCloseReason; 980 _closeReason = _outCloseReason;
977 _subscription.cancel(); 981 if (_subscription != null) _subscription.cancel();
978 _controller.close(); 982 _controller.close();
979 _webSockets.remove(_serviceId); 983 _webSockets.remove(_serviceId);
980 }); 984 });
981 } 985 }
982 } 986 }
983 return _sink.close(); 987 return _sink.close();
984 } 988 }
985 989
986 void _close([int code, String reason]) { 990 void _close([int code, String reason]) {
987 if (_writeClosed) return; 991 if (_writeClosed) return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 (code < WebSocketStatus.NORMAL_CLOSURE || 1030 (code < WebSocketStatus.NORMAL_CLOSURE ||
1027 code == WebSocketStatus.RESERVED_1004 || 1031 code == WebSocketStatus.RESERVED_1004 ||
1028 code == WebSocketStatus.NO_STATUS_RECEIVED || 1032 code == WebSocketStatus.NO_STATUS_RECEIVED ||
1029 code == WebSocketStatus.ABNORMAL_CLOSURE || 1033 code == WebSocketStatus.ABNORMAL_CLOSURE ||
1030 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && 1034 (code > WebSocketStatus.INTERNAL_SERVER_ERROR &&
1031 code < WebSocketStatus.RESERVED_1015) || 1035 code < WebSocketStatus.RESERVED_1015) ||
1032 (code >= WebSocketStatus.RESERVED_1015 && 1036 (code >= WebSocketStatus.RESERVED_1015 &&
1033 code < 3000)); 1037 code < 3000));
1034 } 1038 }
1035 } 1039 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698