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

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

Issue 1072783003: Remove server socket references (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 5 years, 2 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.cc ('k') | sdk/lib/io/socket.dart » ('j') | 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 bool shared: false}) { 10 bool shared: false}) {
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 OSError nativeGetError() native "Socket_GetError"; 1076 OSError nativeGetError() native "Socket_GetError";
1077 nativeGetOption(int option, int protocol) native "Socket_GetOption"; 1077 nativeGetOption(int option, int protocol) native "Socket_GetOption";
1078 bool nativeSetOption(int option, int protocol, value) 1078 bool nativeSetOption(int option, int protocol, value)
1079 native "Socket_SetOption"; 1079 native "Socket_SetOption";
1080 bool nativeJoinMulticast( 1080 bool nativeJoinMulticast(
1081 List<int> addr, List<int> interfaceAddr, int interfaceIndex) 1081 List<int> addr, List<int> interfaceAddr, int interfaceIndex)
1082 native "Socket_JoinMulticast"; 1082 native "Socket_JoinMulticast";
1083 bool nativeLeaveMulticast( 1083 bool nativeLeaveMulticast(
1084 List<int> addr, List<int> interfaceAddr, int interfaceIndex) 1084 List<int> addr, List<int> interfaceAddr, int interfaceIndex)
1085 native "Socket_LeaveMulticast"; 1085 native "Socket_LeaveMulticast";
1086 bool _nativeMarkSocketAsSharedHack()
1087 native "Socket_MarkSocketAsSharedHack";
1088 } 1086 }
1089 1087
1090 1088
1091 class _RawServerSocket extends Stream<RawSocket> 1089 class _RawServerSocket extends Stream<RawSocket>
1092 implements RawServerSocket { 1090 implements RawServerSocket {
1093 final _NativeSocket _socket; 1091 final _NativeSocket _socket;
1094 StreamController<RawSocket> _controller; 1092 StreamController<RawSocket> _controller;
1095 ReceivePort _referencePort; 1093 ReceivePort _referencePort;
1096 bool _v6Only; 1094 bool _v6Only;
1097 1095
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 } 1178 }
1181 1179
1182 void _onPauseStateChange() { 1180 void _onPauseStateChange() {
1183 if (_controller.isPaused) { 1181 if (_controller.isPaused) {
1184 _pause(); 1182 _pause();
1185 } else { 1183 } else {
1186 _resume(); 1184 _resume();
1187 } 1185 }
1188 } 1186 }
1189 1187
1190 RawServerSocketReference get reference {
1191 if (_referencePort == null) {
1192 bool successfull = _socket._nativeMarkSocketAsSharedHack();
1193 _referencePort = new ReceivePort();
1194 _referencePort.listen((sendPort) {
1195 sendPort.send(
1196 [_socket.address,
1197 _socket.port,
1198 _v6Only]);
1199 });
1200 }
1201 return new _RawServerSocketReference(_referencePort.sendPort);
1202 }
1203
1204 void set _owner(owner) { _socket.owner = owner; } 1188 void set _owner(owner) { _socket.owner = owner; }
1205 } 1189 }
1206 1190
1207 1191
1208 class _RawServerSocketReference implements RawServerSocketReference {
1209 final SendPort _sendPort;
1210
1211 _RawServerSocketReference(this._sendPort);
1212
1213 Future<RawServerSocket> create() {
1214 var port = new ReceivePort();
1215 _sendPort.send(port.sendPort);
1216 return port.first.then((List args) {
1217 port.close();
1218
1219 InternetAddress address = args[0];
1220 int tcpPort = args[1];
1221 bool v6Only = args[2];
1222 return
1223 RawServerSocket.bind(address, tcpPort, v6Only: v6Only, shared: true);
1224 });
1225 }
1226
1227 int get hashCode => _sendPort.hashCode;
1228
1229 bool operator==(Object other)
1230 => other is _RawServerSocketReference && _sendPort == other._sendPort;
1231 }
1232
1233
1234 class _RawSocket extends Stream<RawSocketEvent> 1192 class _RawSocket extends Stream<RawSocketEvent>
1235 implements RawSocket { 1193 implements RawSocket {
1236 final _NativeSocket _socket; 1194 final _NativeSocket _socket;
1237 StreamController<RawSocketEvent> _controller; 1195 StreamController<RawSocketEvent> _controller;
1238 bool _readEventsEnabled = true; 1196 bool _readEventsEnabled = true;
1239 bool _writeEventsEnabled = true; 1197 bool _writeEventsEnabled = true;
1240 1198
1241 // Flag to handle Ctrl-D closing of stdio on Mac OS. 1199 // Flag to handle Ctrl-D closing of stdio on Mac OS.
1242 bool _isMacOSTerminalInput = false; 1200 bool _isMacOSTerminalInput = false;
1243 1201
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 /* patch */ static Future<ServerSocket> bind(address, 1344 /* patch */ static Future<ServerSocket> bind(address,
1387 int port, 1345 int port,
1388 {int backlog: 0, 1346 {int backlog: 0,
1389 bool v6Only: false, 1347 bool v6Only: false,
1390 bool shared: false}) { 1348 bool shared: false}) {
1391 return _ServerSocket.bind(address, port, backlog, v6Only, shared); 1349 return _ServerSocket.bind(address, port, backlog, v6Only, shared);
1392 } 1350 }
1393 } 1351 }
1394 1352
1395 1353
1396 class _ServerSocketReference implements ServerSocketReference {
1397 final RawServerSocketReference _rawReference;
1398
1399 _ServerSocketReference(this._rawReference);
1400
1401 Future<ServerSocket> create() {
1402 return _rawReference.create().then((raw) => new _ServerSocket(raw));
1403 }
1404 }
1405
1406
1407 class _ServerSocket extends Stream<Socket> 1354 class _ServerSocket extends Stream<Socket>
1408 implements ServerSocket { 1355 implements ServerSocket {
1409 final _socket; 1356 final _socket;
1410 1357
1411 static Future<_ServerSocket> bind(address, 1358 static Future<_ServerSocket> bind(address,
1412 int port, 1359 int port,
1413 int backlog, 1360 int backlog,
1414 bool v6Only, 1361 bool v6Only,
1415 bool shared) { 1362 bool shared) {
1416 return _RawServerSocket.bind(address, port, backlog, v6Only, shared) 1363 return _RawServerSocket.bind(address, port, backlog, v6Only, shared)
(...skipping 12 matching lines...) Expand all
1429 onDone: onDone, 1376 onDone: onDone,
1430 cancelOnError: cancelOnError); 1377 cancelOnError: cancelOnError);
1431 } 1378 }
1432 1379
1433 int get port => _socket.port; 1380 int get port => _socket.port;
1434 1381
1435 InternetAddress get address => _socket.address; 1382 InternetAddress get address => _socket.address;
1436 1383
1437 Future close() => _socket.close().then((_) => this); 1384 Future close() => _socket.close().then((_) => this);
1438 1385
1439 ServerSocketReference get reference {
1440 return new _ServerSocketReference(_socket.reference);
1441 }
1442
1443 void set _owner(owner) { _socket._owner = owner; } 1386 void set _owner(owner) { _socket._owner = owner; }
1444 } 1387 }
1445 1388
1446 1389
1447 patch class Socket { 1390 patch class Socket {
1448 /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) { 1391 /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) {
1449 return RawSocket.connect(host, port, sourceAddress: sourceAddress).then( 1392 return RawSocket.connect(host, port, sourceAddress: sourceAddress).then(
1450 (socket) => new _Socket(socket)); 1393 (socket) => new _Socket(socket));
1451 } 1394 }
1452 } 1395 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 Datagram _makeDatagram(List<int> data, 1844 Datagram _makeDatagram(List<int> data,
1902 String address, 1845 String address,
1903 List<int> in_addr, 1846 List<int> in_addr,
1904 int port) { 1847 int port) {
1905 return new Datagram( 1848 return new Datagram(
1906 data, 1849 data,
1907 new _InternetAddress(address, null, in_addr), 1850 new _InternetAddress(address, null, in_addr),
1908 port); 1851 port);
1909 } 1852 }
1910 1853
OLDNEW
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/io/socket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698