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

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

Issue 913753002: Reland "Introduce optional 'bool shared' parameter to ServerSocket.bind() ..." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 5 years, 10 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 | « dart/runtime/bin/socket.cc ('k') | dart/sdk/lib/_internal/compiler/js_lib/io_patch.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 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 bool shared: false}) {
11 return _RawServerSocket.bind(address, port, backlog, v6Only, shared);
11 } 12 }
12 } 13 }
13 14
14 15
15 patch class RawSocket { 16 patch class RawSocket {
16 /* patch */ static Future<RawSocket> connect( 17 /* patch */ static Future<RawSocket> connect(
17 host, int port, {sourceAddress}) { 18 host, int port, {sourceAddress}) {
18 return _RawSocket.connect(host, port, sourceAddress); 19 return _RawSocket.connect(host, port, sourceAddress);
19 } 20 }
20 } 21 }
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 467 }
467 } 468 }
468 connectNext(); 469 connectNext();
469 return completer.future; 470 return completer.future;
470 }); 471 });
471 } 472 }
472 473
473 static Future<_NativeSocket> bind(host, 474 static Future<_NativeSocket> bind(host,
474 int port, 475 int port,
475 int backlog, 476 int backlog,
476 bool v6Only) { 477 bool v6Only,
478 bool shared) {
477 return new Future.value(host) 479 return new Future.value(host)
478 .then((host) { 480 .then((host) {
479 if (host is _InternetAddress) return host; 481 if (host is _InternetAddress) return host;
480 return lookup(host) 482 return lookup(host)
481 .then((list) { 483 .then((list) {
482 if (list.length == 0) { 484 if (list.length == 0) {
483 throw createError(response, "Failed host lookup: '$host'"); 485 throw createError(response, "Failed host lookup: '$host'");
484 } 486 }
485 return list[0]; 487 return list[0];
486 }); 488 });
487 }) 489 })
488 .then((address) { 490 .then((address) {
489 var socket = new _NativeSocket.listen(); 491 var socket = new _NativeSocket.listen();
490 socket.address = address; 492 socket.address = address;
493
491 var result = socket.nativeCreateBindListen(address._in_addr, 494 var result = socket.nativeCreateBindListen(address._in_addr,
492 port, 495 port,
493 backlog, 496 backlog,
494 v6Only); 497 v6Only,
498 shared);
495 if (result is OSError) { 499 if (result is OSError) {
496 throw new SocketException("Failed to create server socket", 500 throw new SocketException("Failed to create server socket",
497 osError: result, 501 osError: result,
498 address: address, 502 address: address,
499 port: port); 503 port: port);
500 } 504 }
501 if (port != 0) socket.localPort = port; 505 if (port != 0) socket.localPort = port;
502 socket.connectToEventHandler(); 506 socket.connectToEventHandler();
503 return socket; 507 return socket;
504 }); 508 });
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 nativeWrite(List<int> buffer, int offset, int bytes) 1129 nativeWrite(List<int> buffer, int offset, int bytes)
1126 native "Socket_WriteList"; 1130 native "Socket_WriteList";
1127 nativeSendTo(List<int> buffer, int offset, int bytes, 1131 nativeSendTo(List<int> buffer, int offset, int bytes,
1128 List<int> address, int port) 1132 List<int> address, int port)
1129 native "Socket_SendTo"; 1133 native "Socket_SendTo";
1130 nativeCreateConnect(List<int> addr, 1134 nativeCreateConnect(List<int> addr,
1131 int port) native "Socket_CreateConnect"; 1135 int port) native "Socket_CreateConnect";
1132 nativeCreateBindConnect( 1136 nativeCreateBindConnect(
1133 List<int> addr, int port, List<int> sourceAddr) 1137 List<int> addr, int port, List<int> sourceAddr)
1134 native "Socket_CreateBindConnect"; 1138 native "Socket_CreateBindConnect";
1135 nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only) 1139 nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only,
1140 bool shared)
1136 native "ServerSocket_CreateBindListen"; 1141 native "ServerSocket_CreateBindListen";
1137 nativeCreateBindDatagram(List<int> addr, int port, bool reuseAddress) 1142 nativeCreateBindDatagram(List<int> addr, int port, bool reuseAddress)
1138 native "Socket_CreateBindDatagram"; 1143 native "Socket_CreateBindDatagram";
1139 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; 1144 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept";
1140 int nativeGetPort() native "Socket_GetPort"; 1145 int nativeGetPort() native "Socket_GetPort";
1141 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; 1146 List nativeGetRemotePeer() native "Socket_GetRemotePeer";
1142 int nativeGetSocketId() native "Socket_GetSocketId"; 1147 int nativeGetSocketId() native "Socket_GetSocketId";
1143 OSError nativeGetError() native "Socket_GetError"; 1148 OSError nativeGetError() native "Socket_GetError";
1144 nativeGetOption(int option, int protocol) native "Socket_GetOption"; 1149 nativeGetOption(int option, int protocol) native "Socket_GetOption";
1145 bool nativeSetOption(int option, int protocol, value) 1150 bool nativeSetOption(int option, int protocol, value)
1146 native "Socket_SetOption"; 1151 native "Socket_SetOption";
1147 bool nativeJoinMulticast( 1152 bool nativeJoinMulticast(
1148 List<int> addr, List<int> interfaceAddr, int interfaceIndex) 1153 List<int> addr, List<int> interfaceAddr, int interfaceIndex)
1149 native "Socket_JoinMulticast"; 1154 native "Socket_JoinMulticast";
1150 bool nativeLeaveMulticast( 1155 bool nativeLeaveMulticast(
1151 List<int> addr, List<int> interfaceAddr, int interfaceIndex) 1156 List<int> addr, List<int> interfaceAddr, int interfaceIndex)
1152 native "Socket_LeaveMulticast"; 1157 native "Socket_LeaveMulticast";
1158 bool _nativeMarkSocketAsSharedHack()
1159 native "Socket_MarkSocketAsSharedHack";
1153 } 1160 }
1154 1161
1155 1162
1156 class _RawServerSocket extends Stream<RawSocket> 1163 class _RawServerSocket extends Stream<RawSocket>
1157 implements RawServerSocket { 1164 implements RawServerSocket {
1158 final _NativeSocket _socket; 1165 final _NativeSocket _socket;
1159 StreamController<RawSocket> _controller; 1166 StreamController<RawSocket> _controller;
1160 ReceivePort _referencePort; 1167 ReceivePort _referencePort;
1168 bool _v6Only;
1161 1169
1162 static Future<_RawServerSocket> bind(address, 1170 static Future<_RawServerSocket> bind(address,
1163 int port, 1171 int port,
1164 int backlog, 1172 int backlog,
1165 bool v6Only) { 1173 bool v6Only,
1174 bool shared) {
1166 if (port < 0 || port > 0xFFFF) 1175 if (port < 0 || port > 0xFFFF)
1167 throw new ArgumentError("Invalid port $port"); 1176 throw new ArgumentError("Invalid port $port");
1168 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); 1177 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog");
1169 return _NativeSocket.bind(address, port, backlog, v6Only) 1178 return _NativeSocket.bind(address, port, backlog, v6Only, shared)
1170 .then((socket) => new _RawServerSocket(socket)); 1179 .then((socket) => new _RawServerSocket(socket, v6Only));
1171 } 1180 }
1172 1181
1173 _RawServerSocket(this._socket); 1182 _RawServerSocket(this._socket, this._v6Only);
1174 1183
1175 StreamSubscription<RawSocket> listen(void onData(RawSocket event), 1184 StreamSubscription<RawSocket> listen(void onData(RawSocket event),
1176 {Function onError, 1185 {Function onError,
1177 void onDone(), 1186 void onDone(),
1178 bool cancelOnError}) { 1187 bool cancelOnError}) {
1179 if (_controller != null) { 1188 if (_controller != null) {
1180 throw new StateError("Stream was already listened to"); 1189 throw new StateError("Stream was already listened to");
1181 } 1190 }
1182 var zone = Zone.current; 1191 var zone = Zone.current;
1183 _controller = new StreamController(sync: true, 1192 _controller = new StreamController(sync: true,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 void _onPauseStateChange() { 1254 void _onPauseStateChange() {
1246 if (_controller.isPaused) { 1255 if (_controller.isPaused) {
1247 _pause(); 1256 _pause();
1248 } else { 1257 } else {
1249 _resume(); 1258 _resume();
1250 } 1259 }
1251 } 1260 }
1252 1261
1253 RawServerSocketReference get reference { 1262 RawServerSocketReference get reference {
1254 if (_referencePort == null) { 1263 if (_referencePort == null) {
1264 bool successfull = _socket._nativeMarkSocketAsSharedHack();
1255 _referencePort = new ReceivePort(); 1265 _referencePort = new ReceivePort();
1256 _referencePort.listen((sendPort) { 1266 _referencePort.listen((sendPort) {
1257 sendPort.send( 1267 sendPort.send(
1258 [_socket.nativeGetSocketId(), 1268 [_socket.address,
1259 _socket.address, 1269 _socket.port,
1260 _socket.localPort]); 1270 _v6Only]);
1261 }); 1271 });
1262 } 1272 }
1263 return new _RawServerSocketReference(_referencePort.sendPort); 1273 return new _RawServerSocketReference(_referencePort.sendPort);
1264 } 1274 }
1265 1275
1266 Map _toJSON(bool ref) => _socket._toJSON(ref); 1276 Map _toJSON(bool ref) => _socket._toJSON(ref);
1277
1267 void set _owner(owner) { _socket.owner = owner; } 1278 void set _owner(owner) { _socket.owner = owner; }
1268 } 1279 }
1269 1280
1270 1281
1271 class _RawServerSocketReference implements RawServerSocketReference { 1282 class _RawServerSocketReference implements RawServerSocketReference {
1272 final SendPort _sendPort; 1283 final SendPort _sendPort;
1273 1284
1274 _RawServerSocketReference(this._sendPort); 1285 _RawServerSocketReference(this._sendPort);
1275 1286
1276 Future<RawServerSocket> create() { 1287 Future<RawServerSocket> create() {
1277 var port = new ReceivePort(); 1288 var port = new ReceivePort();
1278 _sendPort.send(port.sendPort); 1289 _sendPort.send(port.sendPort);
1279 return port.first.then((args) { 1290 return port.first.then((List args) {
1280 port.close(); 1291 port.close();
1281 var native = new _NativeSocket.listen(); 1292
1282 native.nativeSetSocketId(args[0]); 1293 InternetAddress address = args[0];
1283 native.address = args[1]; 1294 int tcpPort = args[1];
1284 native.localPort = args[2]; 1295 bool v6Only = args[2];
1285 return new _RawServerSocket(native); 1296 return
1297 RawServerSocket.bind(address, tcpPort, v6Only: v6Only, shared: true);
1286 }); 1298 });
1287 } 1299 }
1288 1300
1289 int get hashCode => _sendPort.hashCode; 1301 int get hashCode => _sendPort.hashCode;
1290 1302
1291 bool operator==(Object other) 1303 bool operator==(Object other)
1292 => other is _RawServerSocketReference && _sendPort == other._sendPort; 1304 => other is _RawServerSocketReference && _sendPort == other._sendPort;
1293 } 1305 }
1294 1306
1295 1307
1296 class _RawSocket extends Stream<RawSocketEvent> 1308 class _RawSocket extends Stream<RawSocketEvent>
1297 implements RawSocket { 1309 implements RawSocket {
1298 final _NativeSocket _socket; 1310 final _NativeSocket _socket;
1299 StreamController<RawSocketEvent> _controller; 1311 StreamController<RawSocketEvent> _controller;
1300 bool _readEventsEnabled = true; 1312 bool _readEventsEnabled = true;
1301 bool _writeEventsEnabled = true; 1313 bool _writeEventsEnabled = true;
1302 1314
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 1453
1442 Map _toJSON(bool ref) => _socket._toJSON(ref); 1454 Map _toJSON(bool ref) => _socket._toJSON(ref);
1443 void set _owner(owner) { _socket.owner = owner; } 1455 void set _owner(owner) { _socket.owner = owner; }
1444 } 1456 }
1445 1457
1446 1458
1447 patch class ServerSocket { 1459 patch class ServerSocket {
1448 /* patch */ static Future<ServerSocket> bind(address, 1460 /* patch */ static Future<ServerSocket> bind(address,
1449 int port, 1461 int port,
1450 {int backlog: 0, 1462 {int backlog: 0,
1451 bool v6Only: false}) { 1463 bool v6Only: false,
1452 return _ServerSocket.bind(address, port, backlog, v6Only); 1464 bool shared: false}) {
1465 return _ServerSocket.bind(address, port, backlog, v6Only, shared);
1453 } 1466 }
1454 } 1467 }
1455 1468
1456 1469
1457 class _ServerSocketReference implements ServerSocketReference { 1470 class _ServerSocketReference implements ServerSocketReference {
1458 final RawServerSocketReference _rawReference; 1471 final RawServerSocketReference _rawReference;
1459 1472
1460 _ServerSocketReference(this._rawReference); 1473 _ServerSocketReference(this._rawReference);
1461 1474
1462 Future<ServerSocket> create() { 1475 Future<ServerSocket> create() {
1463 return _rawReference.create().then((raw) => new _ServerSocket(raw)); 1476 return _rawReference.create().then((raw) => new _ServerSocket(raw));
1464 } 1477 }
1465 } 1478 }
1466 1479
1467 1480
1468 class _ServerSocket extends Stream<Socket> 1481 class _ServerSocket extends Stream<Socket>
1469 implements ServerSocket { 1482 implements ServerSocket {
1470 final _socket; 1483 final _socket;
1471 1484
1472 static Future<_ServerSocket> bind(address, 1485 static Future<_ServerSocket> bind(address,
1473 int port, 1486 int port,
1474 int backlog, 1487 int backlog,
1475 bool v6Only) { 1488 bool v6Only,
1476 return _RawServerSocket.bind(address, port, backlog, v6Only) 1489 bool shared) {
1490 return _RawServerSocket.bind(address, port, backlog, v6Only, shared)
1477 .then((socket) => new _ServerSocket(socket)); 1491 .then((socket) => new _ServerSocket(socket));
1478 } 1492 }
1479 1493
1480 _ServerSocket(this._socket); 1494 _ServerSocket(this._socket);
1481 1495
1482 StreamSubscription<Socket> listen(void onData(Socket event), 1496 StreamSubscription<Socket> listen(void onData(Socket event),
1483 {Function onError, 1497 {Function onError,
1484 void onDone(), 1498 void onDone(),
1485 bool cancelOnError}) { 1499 bool cancelOnError}) {
1486 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( 1500 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen(
1487 onData, 1501 onData,
1488 onError: onError, 1502 onError: onError,
1489 onDone: onDone, 1503 onDone: onDone,
1490 cancelOnError: cancelOnError); 1504 cancelOnError: cancelOnError);
1491 } 1505 }
1492 1506
1493 int get port => _socket.port; 1507 int get port => _socket.port;
1494 1508
1495 InternetAddress get address => _socket.address; 1509 InternetAddress get address => _socket.address;
1496 1510
1497 Future close() => _socket.close().then((_) => this); 1511 Future close() => _socket.close().then((_) => this);
1498 1512
1499 ServerSocketReference get reference { 1513 ServerSocketReference get reference {
1500 return new _ServerSocketReference(_socket.reference); 1514 return new _ServerSocketReference(_socket.reference);
1501 } 1515 }
1502 1516
1503 Map _toJSON(bool ref) => _socket._toJSON(ref); 1517 Map _toJSON(bool ref) => _socket._toJSON(ref);
1518
1504 void set _owner(owner) { _socket._owner = owner; } 1519 void set _owner(owner) { _socket._owner = owner; }
1505 } 1520 }
1506 1521
1507 1522
1508 patch class Socket { 1523 patch class Socket {
1509 /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) { 1524 /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) {
1510 return RawSocket.connect(host, port, sourceAddress: sourceAddress).then( 1525 return RawSocket.connect(host, port, sourceAddress: sourceAddress).then(
1511 (socket) => new _Socket(socket)); 1526 (socket) => new _Socket(socket));
1512 } 1527 }
1513 } 1528 }
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 String address, 1964 String address,
1950 List<int> in_addr, 1965 List<int> in_addr,
1951 int port) { 1966 int port) {
1952 return new Datagram( 1967 return new Datagram(
1953 data, 1968 data,
1954 new _InternetAddress(address, null, in_addr), 1969 new _InternetAddress(address, null, in_addr),
1955 port); 1970 port);
1956 } 1971 }
1957 1972
1958 String _socketsStats() => _SocketsObservatory.toJSON(); 1973 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW
« no previous file with comments | « dart/runtime/bin/socket.cc ('k') | dart/sdk/lib/_internal/compiler/js_lib/io_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698