OLD | NEW |
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 class _WebSocketMessageType { | 9 class _WebSocketMessageType { |
10 static const int NONE = 0; | 10 static const int NONE = 0; |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 _sendFrame(_WebSocketOpcode.CLOSE, data); | 446 _sendFrame(_WebSocketOpcode.CLOSE, data); |
447 | 447 |
448 if (_closeReceived) { | 448 if (_closeReceived) { |
449 // Close the socket when the close frame has been sent - if it | 449 // Close the socket when the close frame has been sent - if it |
450 // does not take too long. | 450 // does not take too long. |
451 _socket.outputStream.close(); | 451 _socket.outputStream.close(); |
452 _socket.outputStream.onClosed = () { | 452 _socket.outputStream.onClosed = () { |
453 if (_closeTimer != null) _closeTimer.cancel(); | 453 if (_closeTimer != null) _closeTimer.cancel(); |
454 _socket.close(); | 454 _socket.close(); |
455 }; | 455 }; |
456 _closeTimer = new Timer(5000, (t) { | 456 _closeTimer = new Timer(const Duration(seconds: 5), _socket.close); |
457 _socket.close(); | |
458 }); | |
459 } else { | 457 } else { |
460 // Half close the socket and expect a close frame in response | 458 // Half close the socket and expect a close frame in response |
461 // before closing the socket. If a close frame does not arrive | 459 // before closing the socket. If a close frame does not arrive |
462 // within a reasonable amount of time just close the socket. | 460 // within a reasonable amount of time just close the socket. |
463 _socket.outputStream.close(); | 461 _socket.outputStream.close(); |
464 _closeTimer = new Timer(5000, (t) { | 462 _closeTimer = new Timer(const Duration(seconds: 5), _socket.close); |
465 _socket.close(); | |
466 }); | |
467 } | 463 } |
468 _closeSent = true; | 464 _closeSent = true; |
469 } | 465 } |
470 | 466 |
471 int get hashCode => _hash; | 467 int get hashCode => _hash; |
472 | 468 |
473 _onWebSocketMessageStart(int type) { | 469 _onWebSocketMessageStart(int type) { |
474 _currentMessageType = type; | 470 _currentMessageType = type; |
475 if (_currentMessageType == _WebSocketMessageType.TEXT) { | 471 if (_currentMessageType == _WebSocketMessageType.TEXT) { |
476 _decoder = _StringDecoders.decoder(Encoding.UTF_8); | 472 _decoder = _StringDecoders.decoder(Encoding.UTF_8); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 863 |
868 class _WebSocketCloseEvent implements CloseEvent { | 864 class _WebSocketCloseEvent implements CloseEvent { |
869 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 865 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
870 bool get wasClean => _wasClean; | 866 bool get wasClean => _wasClean; |
871 int get code => _code; | 867 int get code => _code; |
872 String get reason => _reason; | 868 String get reason => _reason; |
873 bool _wasClean; | 869 bool _wasClean; |
874 int _code; | 870 int _code; |
875 String _reason; | 871 String _reason; |
876 } | 872 } |
OLD | NEW |