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

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: 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
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..9289ca052dd76ccb7e77cbc25455fb505cae50e7 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;
+ _setupWaitOnWrite();
Mads Ager (google) 2012/05/02 08:18:17 I found the name a bit confusing. How about callin
Søren Gjesse 2012/05/02 10:22:45 Done.
} 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 {
+ _setupWaitOnWrite();
+ }
}
}
@@ -154,7 +164,7 @@ class _SocketOutputStream
assert(offset + len == buffer.length);
_pendingWrites.add(buffer, notWrittenOffset);
}
- _socket._onWrite = _onWrite;
+ _setupWaitOnWrite();
return false;
}
@@ -186,6 +196,14 @@ class _SocketOutputStream
}
}
+ void _setupWaitOnWrite() {
Mads Ager (google) 2012/05/02 08:18:17 Can we add a few comments? This sets up a write ha
Søren Gjesse 2012/05/02 10:22:45 Done.
+ if (_noPendingWritesTimer != null) {
+ _noPendingWritesTimer.cancel();
+ _noPendingWritesTimer = null;
+ }
+ _socket._onWrite = _onWrite;
+ }
+
bool _onSocketError(e) {
close();
if (_onError != null) {
@@ -198,7 +216,8 @@ class _SocketOutputStream
Socket _socket;
_BufferList _pendingWrites;
- var _onNoPendingWrites;
+ Function _onNoPendingWrites;
+ Timer _noPendingWritesTimer;
bool _closing = false;
bool _closed = false;
}

Powered by Google App Engine
This is Rietveld 408576698