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

Unified Diff: runtime/bin/socket_stream_impl.dart

Issue 10262031: Add a web socket client (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments 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 | « runtime/bin/http_parser.dart ('k') | runtime/bin/websocket.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 73338d947422efb6a6ad2ab6bbcb194061f52023..cf9f59092b1d4b7a5192086bec9eeda485aee8a3 100644
--- a/runtime/bin/socket_stream_impl.dart
+++ b/runtime/bin/socket_stream_impl.dart
@@ -112,7 +112,7 @@ class _SocketOutputStream
if (!_pendingWrites.isEmpty()) {
// Mark the socket for close when all data is written.
_closing = true;
- _socket._onWrite = _onWrite;
+ _setupWriteHander();
} else {
// Close the socket for writing.
_socket._closeWrite();
@@ -128,9 +128,19 @@ class _SocketOutputStream
}
void set onNoPendingWrites(void callback()) {
+ if (_noPendingWritesTimer != null) {
+ _noPendingWritesTimer.cancel();
+ _noPendingWritesTimer = null;
+ }
_onNoPendingWrites = callback;
if (_onNoPendingWrites != null) {
- _socket._onWrite = _onWrite;
+ if (_pendingWrites.isEmpty()) {
+ _noPendingWritesTimer = new Timer(0, (t) {
+ if (_onNoPendingWrites != null) _onNoPendingWrites();
+ });
+ } else {
+ _setupWriteHander();
+ }
}
}
@@ -154,7 +164,7 @@ class _SocketOutputStream
assert(offset + len == buffer.length);
_pendingWrites.add(buffer, notWrittenOffset);
}
- _socket._onWrite = _onWrite;
+ _setupWriteHander();
return false;
}
@@ -186,6 +196,16 @@ class _SocketOutputStream
}
}
+ void _setupWriteHander() {
+ // Set up the callback for writing the pending data as the
+ // underlying socket becomes ready for writing.
+ if (_noPendingWritesTimer != null) {
+ _noPendingWritesTimer.cancel();
+ _noPendingWritesTimer = null;
+ }
+ _socket._onWrite = _onWrite;
+ }
+
bool _onSocketError(e) {
close();
if (_onError != null) {
@@ -198,7 +218,8 @@ class _SocketOutputStream
Socket _socket;
_BufferList _pendingWrites;
- var _onNoPendingWrites;
+ Function _onNoPendingWrites;
+ Timer _noPendingWritesTimer;
bool _closing = false;
bool _closed = false;
}
« no previous file with comments | « runtime/bin/http_parser.dart ('k') | runtime/bin/websocket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698