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

Unified Diff: sdk/lib/io/http_impl.dart

Issue 302173007: Add HttpServerConnection to Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 6 years, 6 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: sdk/lib/io/http_impl.dart
diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
index 5d1d53598e03a37bcf3a8731819c1c62738df1f8..f9fedc3410bf898fec9521989910eeef3ea6c366 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -1992,13 +1992,18 @@ class _HttpClient implements HttpClient {
}
-class _HttpConnection extends LinkedListEntry<_HttpConnection> {
+class _HttpConnection
+ extends LinkedListEntry<_HttpConnection> with _ServiceObject {
static const _ACTIVE = 0;
static const _IDLE = 1;
static const _CLOSING = 2;
static const _DETACHED = 3;
- final Socket _socket;
+ // Use HashMap, as we don't need to keep order.
+ static Map<int, _HttpConnection> _connections =
+ new HashMap<int, _HttpConnection>();
+
+ final _socket;
final _HttpServer _httpServer;
final _HttpParser _httpParser;
int _state = _IDLE;
@@ -2009,6 +2014,8 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
_HttpConnection(this._socket, this._httpServer)
: _httpParser = new _HttpParser.requestParser() {
+ try { _socket._owner = this; } catch (_) { print(_); }
+ _connections[_serviceId] = this;
_httpParser.listenToStream(_socket);
_subscription = _httpParser.listen(
(incoming) {
@@ -2074,6 +2081,7 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
_state = _CLOSING;
_socket.destroy();
_httpServer._connectionClosed(this);
+ _connections.remove(_serviceId);
}
Future<Socket> detachSocket() {
@@ -2084,6 +2092,7 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
_HttpDetachedIncoming detachedIncoming = _httpParser.detachIncoming();
return _streamFuture.then((_) {
+ _connections.remove(_serviceId);
return new _DetachedSocket(_socket, detachedIncoming);
});
}
@@ -2094,6 +2103,42 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
bool get _isIdle => _state == _IDLE;
bool get _isClosing => _state == _CLOSING;
bool get _isDetached => _state == _DETACHED;
+
+ String get _serviceTypePath => 'io/http/serverconnections';
+ String get _serviceTypeName => 'HttpServerConnection';
+
+ Map _toJSON(bool ref) {
+ var name = "${_socket.address.host}:${_socket.port} <-> "
+ "${_socket.remoteAddress.host}:${_socket.remotePort}";
+ var r = {
+ 'id': _servicePath,
+ 'type': _serviceType(ref),
+ 'name': name,
+ 'user_name': name,
+ };
+ if (ref) {
+ return r;
+ }
+ r['server'] = _httpServer._toJSON(true);
+ try {
+ r['socket'] = _socket._toJSON(true);
+ } catch (_) {
+ r['socket'] = {
+ 'id': _servicePath,
+ 'type': '@Socket',
+ 'name': 'UserSocket',
+ 'user_name': 'UserSocket',
+ };
+ }
+ switch (_state) {
+ case _ACTIVE: r['state'] = "Active"; break;
+ case _IDLE: r['state'] = "Idle"; break;
+ case _CLOSING: r['state'] = "Closing"; break;
+ case _DETACHED: r['state'] = "Detached"; break;
+ default: r['state'] = 'Unknown'; break;
+ }
+ return r;
+ }
}
@@ -2323,8 +2368,8 @@ class _HttpServer
}
r['port'] = port;
r['address'] = address.host;
- r['active'] = _activeConnections.length;
- r['idle'] = _idleConnections.length;
+ r['active'] = _activeConnections.map((c) => c._toJSON(true)).toList();
+ r['idle'] = _idleConnections.map((c) => c._toJSON(true)).toList();
r['closed'] = closed;
return r;
}
« no previous file with comments | « runtime/bin/vmservice/client/lib/src/elements/service_view.dart ('k') | tests/standalone/io/observatory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698