Index: dart/sdk/lib/io/http_impl.dart |
diff --git a/dart/sdk/lib/io/http_impl.dart b/dart/sdk/lib/io/http_impl.dart |
index ab52a2161ba35d4025c0afb1a0545de51294a779..e0557e0c5954d6fbe249c9c4395fea7e5b977c5d 100644 |
--- a/dart/sdk/lib/io/http_impl.dart |
+++ b/dart/sdk/lib/io/http_impl.dart |
@@ -1585,12 +1585,12 @@ class _ConnectionTarget { |
} |
Future<_ConnectionInfo> connect(String uriHost, |
- int uriPort, |
- _Proxy proxy, |
- _HttpClient client) { |
+ int uriPort, |
+ _Proxy proxy, |
+ _HttpClient client) { |
if (hasIdle) { |
var connection = takeIdle(); |
- client._updateTimers(); |
+ client._connectionsChanged(); |
return new Future.value(new _ConnectionInfo(connection, proxy)); |
} |
if (client.maxConnectionsPerHost != null && |
@@ -1640,6 +1640,7 @@ class _ConnectionTarget { |
class _HttpClient implements HttpClient { |
bool _closing = false; |
+ bool _closingForcefully = false; |
final Map<String, _ConnectionTarget> _connectionTargets |
= new HashMap<String, _ConnectionTarget>(); |
final List<_Credentials> _credentials = []; |
@@ -1650,8 +1651,6 @@ class _HttpClient implements HttpClient { |
Duration _idleTimeout = const Duration(seconds: 15); |
Function _badCertificateCallback; |
- Timer _noActiveTimer; |
- |
Duration get idleTimeout => _idleTimeout; |
int maxConnectionsPerHost; |
@@ -1663,7 +1662,7 @@ class _HttpClient implements HttpClient { |
void set idleTimeout(Duration timeout) { |
_idleTimeout = timeout; |
for (var c in _connectionTargets.values) { |
- for (var idle in c.idle) { |
+ for (var idle in c._idle) { |
// Reset timer. This is fine, as it's not happening often. |
idle.stopTimer(); |
idle.startTimer(); |
@@ -1724,7 +1723,8 @@ class _HttpClient implements HttpClient { |
void close({bool force: false}) { |
_closing = true; |
- _connectionTargets.values.toList().forEach((c) => c.close(force)); |
+ _closingForcefully = force; |
+ _closeConnections(_closingForcefully); |
assert(!_connectionTargets.values.any((s) => s.hasIdle)); |
assert(!force || |
!_connectionTargets.values.any((s) => s._active.isNotEmpty)); |
@@ -1827,7 +1827,7 @@ class _HttpClient implements HttpClient { |
// Return a live connection to the idle pool. |
void _returnConnection(_HttpClientConnection connection) { |
_connectionTargets[connection.key].returnConnection(connection); |
- _updateTimers(); |
+ _connectionsChanged(); |
} |
// Remove a closed connnection from the active set. |
@@ -1839,28 +1839,19 @@ class _HttpClient implements HttpClient { |
if (connectionTarget.isEmpty) { |
_connectionTargets.remove(connection.key); |
} |
- _updateTimers(); |
- } |
- } |
- |
- void _updateTimers() { |
- bool hasActive = _connectionTargets.values.any((t) => t.hasActive); |
- if (!hasActive) { |
- bool hasIdle = _connectionTargets.values.any((t) => t.hasIdle); |
- if (hasIdle && _noActiveTimer == null) { |
- _noActiveTimer = new Timer(const Duration(milliseconds: 100), () { |
- _noActiveTimer = null; |
- bool hasActive = |
- _connectionTargets.values.any((t) => t.hasActive); |
- if (!hasActive) { |
- close(); |
- _closing = false; |
- } |
- }); |
- } |
- } else if (_noActiveTimer != null) { |
- _noActiveTimer.cancel(); |
- _noActiveTimer = null; |
+ _connectionsChanged(); |
+ } |
+ } |
+ |
+ void _connectionsChanged() { |
+ if (_closing) { |
+ _closeConnections(_closingForcefully); |
+ } |
+ } |
+ |
+ void _closeConnections(bool force) { |
+ for (var connectionTarget in _connectionTargets.values.toList()) { |
+ connectionTarget.close(force); |
} |
} |
@@ -2016,7 +2007,6 @@ class _HttpConnection |
final _HttpParser _httpParser; |
int _state = _IDLE; |
StreamSubscription _subscription; |
- Timer _idleTimer; |
bool _idleMark = false; |
Future _streamFuture; |