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

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

Issue 198743002: Make the event-handler handle backpreasure. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Doc fix 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/socket_linux.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 static const int RETURN_TOKEN_COMMAND = 11;
358 static const int FIRST_COMMAND = CLOSE_COMMAND; 359 static const int FIRST_COMMAND = CLOSE_COMMAND;
359 static const int LAST_COMMAND = SHUTDOWN_WRITE_COMMAND; 360 static const int LAST_COMMAND = RETURN_TOKEN_COMMAND;
360 361
361 // Type flag send to the eventhandler providing additional 362 // Type flag send to the eventhandler providing additional
362 // information on the type of the file descriptor. 363 // information on the type of the file descriptor.
363 static const int LISTENING_SOCKET = 16; 364 static const int LISTENING_SOCKET = 16;
364 static const int PIPE_SOCKET = 17; 365 static const int PIPE_SOCKET = 17;
365 static const int TYPE_NORMAL_SOCKET = 0; 366 static const int TYPE_NORMAL_SOCKET = 0;
366 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET; 367 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET;
367 static const int TYPE_PIPE = 1 << PIPE_SOCKET; 368 static const int TYPE_PIPE = 1 << PIPE_SOCKET;
368 static const int TYPE_TYPE_MASK = TYPE_LISTENING_SOCKET | PIPE_SOCKET; 369 static const int TYPE_TYPE_MASK = TYPE_LISTENING_SOCKET | PIPE_SOCKET;
369 370
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 if (!isClosing) { 811 if (!isClosing) {
811 reportError(nativeGetError(), ""); 812 reportError(nativeGetError(), "");
812 } 813 }
813 } else if (!isClosed) { 814 } else if (!isClosed) {
814 // If the connection is closed right after it's accepted, there's a 815 // If the connection is closed right after it's accepted, there's a
815 // chance the close-handler is not set. 816 // chance the close-handler is not set.
816 if (handler != null) handler(); 817 if (handler != null) handler();
817 } 818 }
818 } 819 }
819 } 820 }
821 if (eventPort != null && !isClosing && !isClosed) {
822 sendToEventHandler(1 << RETURN_TOKEN_COMMAND);
823 }
820 } 824 }
821 825
822 void setHandlers({read, write, error, closed, destroyed}) { 826 void setHandlers({read, write, error, closed, destroyed}) {
823 eventHandlers[READ_EVENT] = read; 827 eventHandlers[READ_EVENT] = read;
824 eventHandlers[WRITE_EVENT] = write; 828 eventHandlers[WRITE_EVENT] = write;
825 eventHandlers[ERROR_EVENT] = error; 829 eventHandlers[ERROR_EVENT] = error;
826 eventHandlers[CLOSED_EVENT] = closed; 830 eventHandlers[CLOSED_EVENT] = closed;
827 eventHandlers[DESTROYED_EVENT] = destroyed; 831 eventHandlers[DESTROYED_EVENT] = destroyed;
828 } 832 }
829 833
830 void setListening({read: true, write: true}) { 834 void setListening({read: true, write: true}) {
831 sendReadEvents = read; 835 sendReadEvents = read;
832 sendWriteEvents = write; 836 sendWriteEvents = write;
833 if (read) issueReadEvent(); 837 if (read) issueReadEvent();
834 if (write) issueWriteEvent(); 838 if (write) issueWriteEvent();
835 if (eventPort == null) { 839 if (eventPort == null && !isClosing && !isClosed) {
836 int flags = typeFlags & TYPE_TYPE_MASK; 840 int flags = typeFlags & TYPE_TYPE_MASK;
837 if (!isClosedRead) flags |= 1 << READ_EVENT; 841 if (!isClosedRead) flags |= 1 << READ_EVENT;
838 if (!isClosedWrite) flags |= 1 << WRITE_EVENT; 842 if (!isClosedWrite) flags |= 1 << WRITE_EVENT;
839 sendToEventHandler(flags); 843 sendToEventHandler(flags);
840 } 844 }
841 } 845 }
842 846
843 Future close() { 847 Future close() {
844 if (!isClosing && !isClosed) { 848 if (!isClosing && !isClosed) {
845 sendToEventHandler(1 << CLOSE_COMMAND); 849 sendToEventHandler(1 << CLOSE_COMMAND);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 if (isClosedWrite) { 886 if (isClosedWrite) {
883 close(); 887 close();
884 } else { 888 } else {
885 sendToEventHandler(1 << SHUTDOWN_READ_COMMAND); 889 sendToEventHandler(1 << SHUTDOWN_READ_COMMAND);
886 } 890 }
887 isClosedRead = true; 891 isClosedRead = true;
888 } 892 }
889 } 893 }
890 894
891 void sendToEventHandler(int data) { 895 void sendToEventHandler(int data) {
892 assert(!isClosed); 896 assert(!isClosing);
893 connectToEventHandler(); 897 connectToEventHandler();
894 _EventHandler._sendData(this, eventPort, data); 898 _EventHandler._sendData(this, eventPort, data);
895 } 899 }
896 900
897 void connectToEventHandler() { 901 void connectToEventHandler() {
898 if (eventPort == null) { 902 if (eventPort == null) {
899 eventPort = new RawReceivePort(multiplex); 903 eventPort = new RawReceivePort(multiplex);
900 _SocketsObservatory.add(this); 904 _SocketsObservatory.add(this);
901 } 905 }
902 } 906 }
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 String address, 1754 String address,
1751 List<int> in_addr, 1755 List<int> in_addr,
1752 int port) { 1756 int port) {
1753 return new Datagram( 1757 return new Datagram(
1754 data, 1758 data,
1755 new _InternetAddress(address, null, in_addr), 1759 new _InternetAddress(address, null, in_addr),
1756 port); 1760 port);
1757 } 1761 }
1758 1762
1759 String _socketsStats() => _SocketsObservatory.toJSON(); 1763 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698