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

Unified Diff: runtime/bin/socket_stream_impl.dart

Issue 10351009: Implement onClosed on a socket output stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « no previous file | runtime/bin/websocket_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_stream_impl.dart
diff --git a/runtime/bin/socket_stream_impl.dart b/runtime/bin/socket_stream_impl.dart
index ac750b9c091bf8be33c60f7458d78103de011f97..45c7e4d0e763aab00932557f986642d494efa6a6 100644
--- a/runtime/bin/socket_stream_impl.dart
+++ b/runtime/bin/socket_stream_impl.dart
@@ -109,6 +109,7 @@ class _SocketOutputStream
}
void close() {
+ if (_closing && _closed) return;
if (!_pendingWrites.isEmpty()) {
// Mark the socket for close when all data is written.
_closing = true;
@@ -117,6 +118,10 @@ class _SocketOutputStream
// Close the socket for writing.
_socket._closeWrite();
_closed = true;
+ // Invoke the callback asynchronously.
+ new Timer(0, (t) {
+ if (_onClosed != null) _onClosed();
+ });
}
}
@@ -134,6 +139,10 @@ class _SocketOutputStream
}
}
+ void set onClosed(void callback()) {
+ _onClosed = callback;
+ }
+
bool _write(List<int> buffer, int offset, int len, bool copyBuffer) {
if (_closing || _closed) throw new StreamException("Stream closed");
int bytesWritten = 0;
@@ -176,6 +185,9 @@ class _SocketOutputStream
if (_closing) {
_socket._closeWrite();
_closed = true;
+ if (_onClosed != null) {
+ _onClosed();
+ }
} else {
if (_onNoPendingWrites != null) _onNoPendingWrites();
}
@@ -199,6 +211,7 @@ class _SocketOutputStream
Socket _socket;
_BufferList _pendingWrites;
Function _onNoPendingWrites;
+ Function _onClosed;
bool _closing = false;
bool _closed = false;
}
« no previous file with comments | « no previous file | runtime/bin/websocket_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698