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

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 208653012: Only return eventhandler tokens in stacks of 8, to avoid runtime calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review fixes. Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/eventhandler_macos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind(address, 6 /* patch */ static Future<RawServerSocket> bind(address,
7 int port, 7 int port,
8 {int backlog: 0, 8 {int backlog: 0,
9 bool v6Only: false}) { 9 bool v6Only: false}) {
10 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 return _RawServerSocket.bind(address, port, backlog, v6Only);
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 static const int ERROR_EVENT = 2; 348 static const int ERROR_EVENT = 2;
349 static const int CLOSED_EVENT = 3; 349 static const int CLOSED_EVENT = 3;
350 static const int DESTROYED_EVENT = 4; 350 static const int DESTROYED_EVENT = 4;
351 static const int FIRST_EVENT = READ_EVENT; 351 static const int FIRST_EVENT = READ_EVENT;
352 static const int LAST_EVENT = DESTROYED_EVENT; 352 static const int LAST_EVENT = DESTROYED_EVENT;
353 static const int EVENT_COUNT = LAST_EVENT - FIRST_EVENT + 1; 353 static const int EVENT_COUNT = LAST_EVENT - FIRST_EVENT + 1;
354 354
355 static const int CLOSE_COMMAND = 8; 355 static const int CLOSE_COMMAND = 8;
356 static const int SHUTDOWN_READ_COMMAND = 9; 356 static const int SHUTDOWN_READ_COMMAND = 9;
357 static const int SHUTDOWN_WRITE_COMMAND = 10; 357 static const int SHUTDOWN_WRITE_COMMAND = 10;
358 // The lower bits of RETURN_TOKEN_COMMAND messages contains the number
359 // of tokens returned.
358 static const int RETURN_TOKEN_COMMAND = 11; 360 static const int RETURN_TOKEN_COMMAND = 11;
359 static const int FIRST_COMMAND = CLOSE_COMMAND; 361 static const int FIRST_COMMAND = CLOSE_COMMAND;
360 static const int LAST_COMMAND = RETURN_TOKEN_COMMAND; 362 static const int LAST_COMMAND = RETURN_TOKEN_COMMAND;
361 363
362 // Type flag send to the eventhandler providing additional 364 // Type flag send to the eventhandler providing additional
363 // information on the type of the file descriptor. 365 // information on the type of the file descriptor.
364 static const int LISTENING_SOCKET = 16; 366 static const int LISTENING_SOCKET = 16;
365 static const int PIPE_SOCKET = 17; 367 static const int PIPE_SOCKET = 17;
366 static const int TYPE_NORMAL_SOCKET = 0; 368 static const int TYPE_NORMAL_SOCKET = 0;
367 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET; 369 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 final int typeFlags; 405 final int typeFlags;
404 406
405 // Holds the port of the socket, 0 if not known. 407 // Holds the port of the socket, 0 if not known.
406 int localPort = 0; 408 int localPort = 0;
407 409
408 // Holds the address used to connect or bind the socket. 410 // Holds the address used to connect or bind the socket.
409 InternetAddress address; 411 InternetAddress address;
410 412
411 int available = 0; 413 int available = 0;
412 414
415 int returnTokens = 0;
416
413 bool sendReadEvents = false; 417 bool sendReadEvents = false;
414 bool readEventIssued = false; 418 bool readEventIssued = false;
415 419
416 bool sendWriteEvents = false; 420 bool sendWriteEvents = false;
417 bool writeEventIssued = false; 421 bool writeEventIssued = false;
418 bool writeAvailable = false; 422 bool writeAvailable = false;
419 423
420 // Statistics. 424 // Statistics.
421 int totalRead = 0; 425 int totalRead = 0;
422 int totalWritten = 0; 426 int totalWritten = 0;
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 if (!isClosing) { 815 if (!isClosing) {
812 reportError(nativeGetError(), ""); 816 reportError(nativeGetError(), "");
813 } 817 }
814 } else if (!isClosed) { 818 } else if (!isClosed) {
815 // If the connection is closed right after it's accepted, there's a 819 // If the connection is closed right after it's accepted, there's a
816 // chance the close-handler is not set. 820 // chance the close-handler is not set.
817 if (handler != null) handler(); 821 if (handler != null) handler();
818 } 822 }
819 } 823 }
820 } 824 }
821 if (eventPort != null && !isClosing && !isClosed) { 825 if (eventPort != null && !isClosing && !isClosed && !isListening) {
822 sendToEventHandler(1 << RETURN_TOKEN_COMMAND); 826 returnTokens++;
827 if (returnTokens == 8) {
828 // Return in batches of 8.
829 assert(returnTokens < (1 << FIRST_COMMAND));
830 sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | returnTokens);
831 returnTokens = 0;
832 }
823 } 833 }
824 } 834 }
825 835
826 void setHandlers({read, write, error, closed, destroyed}) { 836 void setHandlers({read, write, error, closed, destroyed}) {
827 eventHandlers[READ_EVENT] = read; 837 eventHandlers[READ_EVENT] = read;
828 eventHandlers[WRITE_EVENT] = write; 838 eventHandlers[WRITE_EVENT] = write;
829 eventHandlers[ERROR_EVENT] = error; 839 eventHandlers[ERROR_EVENT] = error;
830 eventHandlers[CLOSED_EVENT] = closed; 840 eventHandlers[CLOSED_EVENT] = closed;
831 eventHandlers[DESTROYED_EVENT] = destroyed; 841 eventHandlers[DESTROYED_EVENT] = destroyed;
832 } 842 }
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 String address, 1764 String address,
1755 List<int> in_addr, 1765 List<int> in_addr,
1756 int port) { 1766 int port) {
1757 return new Datagram( 1767 return new Datagram(
1758 data, 1768 data,
1759 new _InternetAddress(address, null, in_addr), 1769 new _InternetAddress(address, null, in_addr),
1760 port); 1770 port);
1761 } 1771 }
1762 1772
1763 String _socketsStats() => _SocketsObservatory.toJSON(); 1773 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW
« 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