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

Unified Diff: runtime/bin/socket_patch.dart

Issue 250513002: Add support for cloning server-sockets. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index 59faecf0918c3ea10c5095c9c5acee4f079f2490..f771a63ed4f7f5760f3164092e42601e42bee177 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -838,8 +838,8 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
void returnTokens() {
if (eventPort != null && !isClosing && !isClosed) {
- if (tokens == 8) {
- // Return in batches of 8.
+ if (tokens == 2) {
Søren Gjesse 2014/04/25 12:24:44 Please add a constant for this.
Anders Johnsen 2014/05/01 11:34:50 Done.
+ // Return in batches of 2.
assert(tokens < (1 << FIRST_COMMAND));
sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | tokens);
tokens = 0;
@@ -1053,6 +1053,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
nativeAccept(_NativeSocket socket) native "ServerSocket_Accept";
int nativeGetPort() native "Socket_GetPort";
List nativeGetRemotePeer() native "Socket_GetRemotePeer";
+ int nativeGetSocketId() native "Socket_GetSocketId";
OSError nativeGetError() native "Socket_GetError";
nativeGetOption(int option, int protocol) native "Socket_GetOption";
bool nativeSetOption(int option, int protocol, value)
@@ -1147,6 +1148,38 @@ class _RawServerSocket extends Stream<RawSocket>
_resume();
}
}
+
+ RawServerSocketHandle clone() {
+ var port = new ReceivePort();
+ port.first.then((sendPort) {
+ sendPort.send(
+ [_socket.nativeGetSocketId(),
+ _socket.address,
+ _socket.localPort]);
+ port.close();
+ });
+ return new _RawServerSocketHandle(port.sendPort);
+ }
+}
+
+
+class _RawServerSocketHandle implements RawServerSocketHandle {
+ final SendPort _sendPort;
+
+ _RawServerSocketHandle(this._sendPort);
+
+ Future<RawServerSocket> acquire() {
+ var port = new ReceivePort();
+ _sendPort.send(port.sendPort);
+ return port.first.then((args) {
+ port.close();
+ var native = new _NativeSocket.listen();
+ native.nativeSetSocketId(args[0]);
+ native.address = args[1];
+ native.localPort = args[2];
+ return new _RawServerSocket(native);
+ });
+ }
}
@@ -1307,6 +1340,18 @@ patch class ServerSocket {
}
}
+
+class _ServerSocketHandle implements ServerSocketHandle {
+ final RawServerSocketHandle _rawHandle;
+
+ _ServerSocketHandle(this._rawHandle);
+
+ Future<ServerSocket> acquire() {
+ return _rawHandle.acquire().then((raw) => new _ServerSocket(raw));
+ }
+}
+
+
class _ServerSocket extends Stream<Socket>
implements ServerSocket {
final _socket;
@@ -1337,6 +1382,10 @@ class _ServerSocket extends Stream<Socket>
InternetAddress get address => _socket.address;
Future close() => _socket.close().then((_) => this);
+
+ ServerSocketHandle clone() {
+ return new _ServerSocketHandle(_socket.clone());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698