Index: runtime/bin/socket_patch.dart |
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart |
index 0e7abdb4bf98b0f310f54bf90f848b97838de460..b46bf5ea4ca0aaee21e7d78918d0ce9ccdeb5e01 100644 |
--- a/runtime/bin/socket_patch.dart |
+++ b/runtime/bin/socket_patch.dart |
@@ -355,6 +355,8 @@ class _NativeSocket extends NativeFieldWrapperClass1 { |
static const int CLOSE_COMMAND = 8; |
static const int SHUTDOWN_READ_COMMAND = 9; |
static const int SHUTDOWN_WRITE_COMMAND = 10; |
+ // The lower bits of RETURN_TOKEN_COMMAND messages contains the number |
+ // of tokens returned. |
static const int RETURN_TOKEN_COMMAND = 11; |
static const int FIRST_COMMAND = CLOSE_COMMAND; |
static const int LAST_COMMAND = RETURN_TOKEN_COMMAND; |
@@ -410,6 +412,8 @@ class _NativeSocket extends NativeFieldWrapperClass1 { |
int available = 0; |
+ int returnTokens = 0; |
+ |
bool sendReadEvents = false; |
bool readEventIssued = false; |
@@ -818,8 +822,14 @@ class _NativeSocket extends NativeFieldWrapperClass1 { |
} |
} |
} |
- if (eventPort != null && !isClosing && !isClosed) { |
- sendToEventHandler(1 << RETURN_TOKEN_COMMAND); |
+ if (eventPort != null && !isClosing && !isClosed && !isListening) { |
+ returnTokens++; |
+ if (returnTokens == 8) { |
+ // Return in batches of 8. |
+ assert(returnTokens < (1 << FIRST_COMMAND)); |
+ sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | returnTokens); |
+ returnTokens = 0; |
+ } |
} |
} |