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

Unified Diff: runtime/bin/socket_patch.dart

Issue 297213005: Add Socket ref to HttpServer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Deploy Created 6 years, 7 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
« no previous file with comments | « runtime/bin/service_object_patch.dart ('k') | runtime/bin/vmservice/client/deployed/web/index.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index 7445562d6707a364f9b78be928cbf0fc11f008df..ebe557fe076737dc2db7538acddfc01895805cae 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -332,8 +332,13 @@ class _SocketsObservatory {
}
+// The NativeFieldWrapperClass1 can not be used with a mixin, due to missing
+// implicit constructor.
+class _NativeSocketNativeWrapper extends NativeFieldWrapperClass1 {}
+
+
// The _NativeSocket class encapsulates an OS socket.
-class _NativeSocket extends NativeFieldWrapperClass1 {
+class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
// Bit flags used when communicating between the eventhandler and
// dart code. The EVENT flags are used to indicate events of
// interest when sending a message from dart code to the
@@ -393,6 +398,9 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
static const int NORMAL_TOKEN_BATCH_SIZE = 8;
static const int LISTENING_TOKEN_BATCH_SIZE = 2;
+ // Use default Map so we keep order.
+ static Map<int, _NativeSocket> _sockets = new Map<int, _NativeSocket>();
+
// Socket close state
bool isClosed = false;
bool isClosing = false;
@@ -600,7 +608,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
_NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET | TYPE_TCP_SOCKET;
- _NativeSocket.listen() : typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET;
+ _NativeSocket.listen() : super(), typeFlags = TYPE_LISTENING_SOCKET | TYPE_TCP_SOCKET;
_NativeSocket.pipe() : typeFlags = TYPE_PIPE;
@@ -943,7 +951,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
assert(!isClosed);
if (eventPort == null) {
eventPort = new RawReceivePort(multiplex);
- _SocketsObservatory.add(this);
+ _sockets[_serviceId] = this;
}
}
@@ -951,7 +959,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
assert(eventPort != null);
eventPort.close();
eventPort = null;
- _SocketsObservatory.remove(this);
+ _sockets.remove(_serviceId);
}
// Check whether this is an error response from a native port call.
@@ -1053,6 +1061,24 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
if (result is OSError) throw result;
}
+ String get _serviceTypePath => 'io/socket';
+ String get _serviceTypeName => 'Socket';
+
+ Map _toJSON(bool ref) {
+ var r = {
+ 'id': _servicePath,
+ 'type': _serviceType(ref),
+ 'name': '${address.host}:$port',
+ 'user_name': '${address.host}:$port',
+ };
+ if (ref) {
+ return r;
+ }
+ r['port'] = port;
+ r['address'] = address.host;
+ return r;
+ }
+
void nativeSetSocketId(int id) native "Socket_SetSocketId";
nativeAvailable() native "Socket_Available";
nativeRead(int len) native "Socket_Read";
@@ -1185,6 +1211,8 @@ class _RawServerSocket extends Stream<RawSocket>
}
return new _RawServerSocketReference(_referencePort.sendPort);
}
+
+ Map _toJSON(bool ref) => _socket._toJSON(ref);
}
@@ -1416,6 +1444,8 @@ class _ServerSocket extends Stream<Socket>
ServerSocketReference get reference {
return new _ServerSocketReference(_socket.reference);
}
+
+ Map _toJSON(bool ref) => _socket._toJSON(ref);
}
« no previous file with comments | « runtime/bin/service_object_patch.dart ('k') | runtime/bin/vmservice/client/deployed/web/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698