Index: dart/runtime/bin/socket_patch.dart |
diff --git a/dart/runtime/bin/socket_patch.dart b/dart/runtime/bin/socket_patch.dart |
index c2cc58705509374020f048e7184231d4c045c3e2..dff4535a4dfa69436372753c511693edcc8363b3 100644 |
--- a/dart/runtime/bin/socket_patch.dart |
+++ b/dart/runtime/bin/socket_patch.dart |
@@ -6,8 +6,9 @@ patch class RawServerSocket { |
/* patch */ static Future<RawServerSocket> bind(address, |
int port, |
{int backlog: 0, |
- bool v6Only: false}) { |
- return _RawServerSocket.bind(address, port, backlog, v6Only); |
+ bool v6Only: false, |
+ bool shared: false}) { |
+ return _RawServerSocket.bind(address, port, backlog, v6Only, shared); |
} |
} |
@@ -459,7 +460,8 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
static Future<_NativeSocket> bind(host, |
int port, |
int backlog, |
- bool v6Only) { |
+ bool v6Only, |
+ bool shared) { |
return new Future.value(host) |
.then((host) { |
if (host is _InternetAddress) return host; |
@@ -474,10 +476,12 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
.then((address) { |
var socket = new _NativeSocket.listen(); |
socket.address = address; |
+ |
var result = socket.nativeCreateBindListen(address._in_addr, |
port, |
backlog, |
- v6Only); |
+ v6Only, |
+ shared); |
if (result is OSError) { |
throw new SocketException("Failed to create server socket", |
osError: result, |
@@ -523,7 +527,9 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
_NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET | TYPE_TCP_SOCKET; |
- _NativeSocket.listen() : typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET; |
+ _NativeSocket.listen() : typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET { |
+ isClosedWrite = true; |
+ } |
_NativeSocket.pipe() : typeFlags = TYPE_PIPE; |
@@ -1113,7 +1119,8 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
native "Socket_SendTo"; |
nativeCreateConnect(List<int> addr, |
int port) native "Socket_CreateConnect"; |
- nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only) |
+ nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only, |
+ bool shared) |
native "ServerSocket_CreateBindListen"; |
nativeCreateBindDatagram(List<int> addr, int port, bool reuseAddress) |
native "Socket_CreateBindDatagram"; |
@@ -1131,6 +1138,8 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
bool nativeLeaveMulticast( |
List<int> addr, List<int> interfaceAddr, int interfaceIndex) |
native "Socket_LeaveMulticast"; |
+ bool _nativeMarkSocketAsSharedHack() |
+ native "Socket_MarkSocketAsSharedHack"; |
} |
@@ -1139,19 +1148,21 @@ class _RawServerSocket extends Stream<RawSocket> |
final _NativeSocket _socket; |
StreamController<RawSocket> _controller; |
ReceivePort _referencePort; |
+ bool _v6Only; |
static Future<_RawServerSocket> bind(address, |
int port, |
int backlog, |
- bool v6Only) { |
+ bool v6Only, |
+ bool shared) { |
if (port < 0 || port > 0xFFFF) |
throw new ArgumentError("Invalid port $port"); |
if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); |
- return _NativeSocket.bind(address, port, backlog, v6Only) |
- .then((socket) => new _RawServerSocket(socket)); |
+ return _NativeSocket.bind(address, port, backlog, v6Only, shared) |
+ .then((socket) => new _RawServerSocket(socket, v6Only)); |
} |
- _RawServerSocket(this._socket); |
+ _RawServerSocket(this._socket, this._v6Only); |
StreamSubscription<RawSocket> listen(void onData(RawSocket event), |
{Function onError, |
@@ -1233,18 +1244,20 @@ class _RawServerSocket extends Stream<RawSocket> |
RawServerSocketReference get reference { |
if (_referencePort == null) { |
+ bool successfull = _socket._nativeMarkSocketAsSharedHack(); |
_referencePort = new ReceivePort(); |
_referencePort.listen((sendPort) { |
sendPort.send( |
- [_socket.nativeGetSocketId(), |
- _socket.address, |
- _socket.localPort]); |
+ [_socket.address, |
+ _socket.port, |
+ _v6Only]); |
}); |
} |
return new _RawServerSocketReference(_referencePort.sendPort); |
} |
Map _toJSON(bool ref) => _socket._toJSON(ref); |
+ |
void set _owner(owner) { _socket.owner = owner; } |
} |
@@ -1257,20 +1270,21 @@ class _RawServerSocketReference implements RawServerSocketReference { |
Future<RawServerSocket> create() { |
var port = new ReceivePort(); |
_sendPort.send(port.sendPort); |
- return port.first.then((args) { |
+ return port.first.then((List args) { |
port.close(); |
- var native = new _NativeSocket.listen(); |
- native.nativeSetSocketId(args[0]); |
- native.address = args[1]; |
- native.localPort = args[2]; |
- return new _RawServerSocket(native); |
+ |
+ InternetAddress address = args[0]; |
+ int tcpPort = args[1]; |
+ bool v6Only = args[2]; |
+ return |
+ RawServerSocket.bind(address, tcpPort, v6Only: v6Only, shared: true); |
}); |
} |
int get hashCode => _sendPort.hashCode; |
bool operator==(Object other) |
- => other is _RawServerSocketReference && _sendPort == other._sendPort; |
+ => other is _RawServerSocketReference && _sendPort == other._sendPort; |
} |
@@ -1429,8 +1443,9 @@ patch class ServerSocket { |
/* patch */ static Future<ServerSocket> bind(address, |
int port, |
{int backlog: 0, |
- bool v6Only: false}) { |
- return _ServerSocket.bind(address, port, backlog, v6Only); |
+ bool v6Only: false, |
+ bool shared: false}) { |
+ return _ServerSocket.bind(address, port, backlog, v6Only, shared); |
} |
} |
@@ -1453,8 +1468,9 @@ class _ServerSocket extends Stream<Socket> |
static Future<_ServerSocket> bind(address, |
int port, |
int backlog, |
- bool v6Only) { |
- return _RawServerSocket.bind(address, port, backlog, v6Only) |
+ bool v6Only, |
+ bool shared) { |
+ return _RawServerSocket.bind(address, port, backlog, v6Only, shared) |
.then((socket) => new _ServerSocket(socket)); |
} |
@@ -1482,6 +1498,7 @@ class _ServerSocket extends Stream<Socket> |
} |
Map _toJSON(bool ref) => _socket._toJSON(ref); |
+ |
void set _owner(owner) { _socket._owner = owner; } |
} |