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

Unified Diff: runtime/bin/socket_patch.dart

Issue 234843003: Make server-sockets level triggered. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix platforms. Created 6 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/eventhandler_macos.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index f31975e30242d672173abe8f9ab049b68b4e9098..59faecf0918c3ea10c5095c9c5acee4f079f2490 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -412,7 +412,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
int available = 0;
- int returnTokens = 0;
+ int tokens = 0;
bool sendReadEvents = false;
bool readEventIssued = false;
@@ -696,6 +696,10 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
_NativeSocket accept() {
// Don't issue accept if we're closing.
if (isClosing || isClosed) return null;
+ assert(available > 0);
+ available--;
+ tokens++;
+ returnTokens();
var socket = new _NativeSocket.normal();
if (nativeAccept(socket) != true) return null;
socket.localPort = localPort;
@@ -788,17 +792,21 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
continue;
}
- if (i == READ_EVENT && !isListening) {
- var avail = nativeAvailable();
- if (avail is int) {
- available = avail;
+ if (i == READ_EVENT) {
+ if (isListening) {
+ available++;
} else {
- // Available failed. Mark socket as having data, to ensure read
- // events, and thus reporting of this error.
- available = 1;
+ var avail = nativeAvailable();
+ if (avail is int) {
+ available = avail;
+ } else {
+ // Available failed. Mark socket as having data, to ensure read
+ // events, and thus reporting of this error.
+ available = 1;
+ }
+ issueReadEvent();
+ continue;
}
- issueReadEvent();
- continue;
}
var handler = eventHandlers[i];
@@ -822,13 +830,19 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
}
}
}
- if (eventPort != null && !isClosing && !isClosed && !isListening) {
- returnTokens++;
- if (returnTokens == 8) {
+ if (!isListening) {
+ tokens++;
+ returnTokens();
+ }
+ }
+
+ void returnTokens() {
+ if (eventPort != null && !isClosing && !isClosed) {
+ if (tokens == 8) {
// Return in batches of 8.
- assert(returnTokens < (1 << FIRST_COMMAND));
- sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | returnTokens);
- returnTokens = 0;
+ assert(tokens < (1 << FIRST_COMMAND));
+ sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | tokens);
+ tokens = 0;
}
}
}
@@ -1085,11 +1099,12 @@ class _RawServerSocket extends Stream<RawSocket>
onResume: _onPauseStateChange);
_socket.setHandlers(
read: zone.bindCallback(() {
- do {
+ while (_socket.available > 0) {
var socket = _socket.accept();
if (socket == null) return;
_controller.add(new _RawSocket(socket));
- } while (!_controller.isPaused);
+ if (_controller.isPaused) return;
+ }
}),
error: zone.bindUnaryCallback((e) {
_controller.addError(e);
« no previous file with comments | « runtime/bin/eventhandler_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698