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

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

Issue 1133673006: Make sure to process WebSocket frames when closing a WebSocket (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 5 years, 7 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/web_socket_pipe_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 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 Future get done => _sink.done; 952 Future get done => _sink.done;
953 953
954 Future close([int code, String reason]) { 954 Future close([int code, String reason]) {
955 if (_isReservedStatusCode(code)) { 955 if (_isReservedStatusCode(code)) {
956 throw new WebSocketException("Reserved status code $code"); 956 throw new WebSocketException("Reserved status code $code");
957 } 957 }
958 if (_outCloseCode == null) { 958 if (_outCloseCode == null) {
959 _outCloseCode = code; 959 _outCloseCode = code;
960 _outCloseReason = reason; 960 _outCloseReason = reason;
961 } 961 }
962 if (_closeTimer == null && !_controller.isClosed) { 962 if (!_controller.isClosed) {
963 // When closing the web-socket, we no longer accept data. 963 // If a close has not yet been received from the other end then
964 _closeTimer = new Timer(const Duration(seconds: 5), () { 964 // 1) make sure to listen on the stream so the close frame will be
965 // Reuse code and reason from the local close. 965 // processed if received.
966 _closeCode = _outCloseCode; 966 // 2) set a timer terminate the connection if a close frame is
967 _closeReason = _outCloseReason; 967 // not received.
968 _subscription.cancel(); 968 if (!_controller.hasListener) {
969 _controller.close(); 969 _controller.stream.drain().catchError((_) => {});
970 _webSockets.remove(_serviceId); 970 }
971 }); 971 if (_closeTimer == null) {
972 // When closing the web-socket, we no longer accept data.
973 _closeTimer = new Timer(const Duration(seconds: 5), () {
974 // Reuse code and reason from the local close.
975 _closeCode = _outCloseCode;
976 _closeReason = _outCloseReason;
977 _subscription.cancel();
978 _controller.close();
979 _webSockets.remove(_serviceId);
980 });
981 }
972 } 982 }
973 return _sink.close(); 983 return _sink.close();
974 } 984 }
975 985
976 void _close([int code, String reason]) { 986 void _close([int code, String reason]) {
977 if (_writeClosed) return; 987 if (_writeClosed) return;
978 if (_outCloseCode == null) { 988 if (_outCloseCode == null) {
979 _outCloseCode = code; 989 _outCloseCode = code;
980 _outCloseReason = reason; 990 _outCloseReason = reason;
981 } 991 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 (code < WebSocketStatus.NORMAL_CLOSURE || 1026 (code < WebSocketStatus.NORMAL_CLOSURE ||
1017 code == WebSocketStatus.RESERVED_1004 || 1027 code == WebSocketStatus.RESERVED_1004 ||
1018 code == WebSocketStatus.NO_STATUS_RECEIVED || 1028 code == WebSocketStatus.NO_STATUS_RECEIVED ||
1019 code == WebSocketStatus.ABNORMAL_CLOSURE || 1029 code == WebSocketStatus.ABNORMAL_CLOSURE ||
1020 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && 1030 (code > WebSocketStatus.INTERNAL_SERVER_ERROR &&
1021 code < WebSocketStatus.RESERVED_1015) || 1031 code < WebSocketStatus.RESERVED_1015) ||
1022 (code >= WebSocketStatus.RESERVED_1015 && 1032 (code >= WebSocketStatus.RESERVED_1015 &&
1023 code < 3000)); 1033 code < 3000));
1024 } 1034 }
1025 } 1035 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/web_socket_pipe_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698