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

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

Issue 665823007: Several bugfixes in dart:io's handing of sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added two spaces as requested Created 6 years, 1 month 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
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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 eventHandlers[DESTROYED_EVENT] = destroyed; 798 eventHandlers[DESTROYED_EVENT] = destroyed;
799 } 799 }
800 800
801 void setListening({read: true, write: true}) { 801 void setListening({read: true, write: true}) {
802 sendReadEvents = read; 802 sendReadEvents = read;
803 sendWriteEvents = write; 803 sendWriteEvents = write;
804 if (read) issueReadEvent(); 804 if (read) issueReadEvent();
805 if (write) issueWriteEvent(); 805 if (write) issueWriteEvent();
806 if (!flagsSent && !isClosing) { 806 if (!flagsSent && !isClosing) {
807 flagsSent = true; 807 flagsSent = true;
808 int flags = typeFlags & TYPE_TYPE_MASK; 808 int flags = 0;
809 if (!isClosedRead) flags |= 1 << READ_EVENT; 809 if (!isClosedRead) flags |= 1 << READ_EVENT;
810 if (!isClosedWrite) flags |= 1 << WRITE_EVENT; 810 if (!isClosedWrite) flags |= 1 << WRITE_EVENT;
811 sendToEventHandler(flags); 811 sendToEventHandler(flags);
812 } 812 }
813 } 813 }
814 814
815 Future close() { 815 Future close() {
816 if (!isClosing && !isClosed) { 816 if (!isClosing && !isClosed) {
817 sendToEventHandler(1 << CLOSE_COMMAND); 817 sendToEventHandler(1 << CLOSE_COMMAND);
818 isClosing = true; 818 isClosing = true;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 if (isClosedWrite) { 854 if (isClosedWrite) {
855 close(); 855 close();
856 } else { 856 } else {
857 sendToEventHandler(1 << SHUTDOWN_READ_COMMAND); 857 sendToEventHandler(1 << SHUTDOWN_READ_COMMAND);
858 } 858 }
859 isClosedRead = true; 859 isClosedRead = true;
860 } 860 }
861 } 861 }
862 862
863 void sendToEventHandler(int data) { 863 void sendToEventHandler(int data) {
864 int fullData = (typeFlags & TYPE_TYPE_MASK) | data;
864 assert(!isClosing); 865 assert(!isClosing);
865 connectToEventHandler(); 866 connectToEventHandler();
866 _EventHandler._sendData(this, eventPort.sendPort, data); 867 _EventHandler._sendData(this, eventPort.sendPort, fullData);
867 } 868 }
868 869
869 void connectToEventHandler() { 870 void connectToEventHandler() {
870 assert(!isClosed); 871 assert(!isClosed);
871 if (eventPort == null) { 872 if (eventPort == null) {
872 eventPort = new RawReceivePort(multiplex); 873 eventPort = new RawReceivePort(multiplex);
873 _sockets[_serviceId] = this; 874 _sockets[_serviceId] = this;
874 } 875 }
875 } 876 }
876 877
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 } 1176 }
1176 }), 1177 }),
1177 error: zone.bindUnaryCallback((e) { 1178 error: zone.bindUnaryCallback((e) {
1178 _controller.addError(e); 1179 _controller.addError(e);
1179 _controller.close(); 1180 _controller.close();
1180 }), 1181 }),
1181 destroyed: () { 1182 destroyed: () {
1182 _controller.close(); 1183 _controller.close();
1183 if (_referencePort != null) { 1184 if (_referencePort != null) {
1184 _referencePort.close(); 1185 _referencePort.close();
1186 _referencePort = null;
1185 } 1187 }
1186 }); 1188 });
1187 return _controller.stream.listen( 1189 return _controller.stream.listen(
1188 onData, 1190 onData,
1189 onError: onError, 1191 onError: onError,
1190 onDone: onDone, 1192 onDone: onDone,
1191 cancelOnError: cancelOnError); 1193 cancelOnError: cancelOnError);
1192 } 1194 }
1193 1195
1194 int get port => _socket.port; 1196 int get port => _socket.port;
1195 1197
1196 InternetAddress get address => _socket.address; 1198 InternetAddress get address => _socket.address;
1197 1199
1198 Future close() => _socket.close().then((_) => this); 1200 Future close() {
1201 return _socket.close().then((_) {
1202 if (_referencePort != null) {
1203 _referencePort.close();
1204 _referencePort = null;
1205 }
1206 return this;
1207 });
1208 }
1199 1209
1200 void _pause() { 1210 void _pause() {
1201 _socket.setListening(read: false, write: false); 1211 _socket.setListening(read: false, write: false);
1202 } 1212 }
1203 1213
1204 void _resume() { 1214 void _resume() {
1205 _socket.setListening(read: true, write: false); 1215 _socket.setListening(read: true, write: false);
1206 } 1216 }
1207 1217
1208 void _onSubscriptionStateChange() { 1218 void _onSubscriptionStateChange() {
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 String address, 1930 String address,
1921 List<int> in_addr, 1931 List<int> in_addr,
1922 int port) { 1932 int port) {
1923 return new Datagram( 1933 return new Datagram(
1924 data, 1934 data,
1925 new _InternetAddress(address, null, in_addr), 1935 new _InternetAddress(address, null, in_addr),
1926 port); 1936 port);
1927 } 1937 }
1928 1938
1929 String _socketsStats() => _SocketsObservatory.toJSON(); 1939 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698