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

Unified Diff: sdk/lib/io/websocket_impl.dart

Issue 169383003: Make event-handlers edge-triggered and move socket-state to Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/secure_socket.dart ('k') | tests/standalone/io/http_no_reason_phrase_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/websocket_impl.dart
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart
index b169afac76c40f4d8f8a88b695b861e6599c162f..ee56378d788a279caf39372d7084f05931c712b9 100644
--- a/sdk/lib/io/websocket_impl.dart
+++ b/sdk/lib/io/websocket_impl.dart
@@ -781,6 +781,7 @@ class _WebSocketImpl extends Stream implements WebSocket {
int _outCloseCode;
String _outCloseReason;
+ Timer _closeTimer;
static final HttpClient _httpClient = new HttpClient();
@@ -879,6 +880,7 @@ class _WebSocketImpl extends Stream implements WebSocket {
}
},
onError: (error) {
+ if (_closeTimer != null) _closeTimer.cancel();
if (error is FormatException) {
_close(WebSocketStatus.INVALID_FRAME_PAYLOAD_DATA);
} else {
@@ -887,6 +889,7 @@ class _WebSocketImpl extends Stream implements WebSocket {
_controller.close();
},
onDone: () {
+ if (_closeTimer != null) _closeTimer.cancel();
if (_readyState == WebSocket.OPEN) {
_readyState = WebSocket.CLOSING;
if (!_isReservedStatusCode(transformer.closeCode)) {
@@ -957,6 +960,13 @@ class _WebSocketImpl extends Stream implements WebSocket {
_outCloseCode = code;
_outCloseReason = reason;
}
+ if (_closeTimer == null && !_controller.isClosed) {
+ // When closing the web-socket, we no longer accept data.
+ _closeTimer = new Timer(const Duration(seconds: 5), () {
+ _subscription.cancel();
+ _controller.close();
+ });
+ }
return _sink.close();
}
« no previous file with comments | « sdk/lib/io/secure_socket.dart ('k') | tests/standalone/io/http_no_reason_phrase_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698