| Index: sdk/lib/io/http_impl.dart
|
| diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
|
| index 615c59aeb873ab305fed79cb737feeef988eff91..7eaf153f32f879ecb7e82a556766b7bf0448e542 100644
|
| --- a/sdk/lib/io/http_impl.dart
|
| +++ b/sdk/lib/io/http_impl.dart
|
| @@ -1824,14 +1824,17 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
|
| final _HttpServer _httpServer;
|
| final _HttpParser _httpParser;
|
| StreamSubscription _subscription;
|
| + Timer _idleTimer;
|
|
|
| Future _streamFuture;
|
|
|
| _HttpConnection(Socket this._socket, _HttpServer this._httpServer)
|
| : _httpParser = new _HttpParser.requestParser() {
|
| + _startTimeout();
|
| _socket.pipe(_httpParser);
|
| _subscription = _httpParser.listen(
|
| (incoming) {
|
| + _stopTimeout();
|
| // If the incoming was closed, close the connection.
|
| incoming.dataDone.then((closing) {
|
| if (closing) destroy();
|
| @@ -1854,6 +1857,7 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
|
| request.persistentConnection &&
|
| incoming.fullBodyRead) {
|
| _state = _IDLE;
|
| + _startTimeout();
|
| // Resume the subscription for incoming requests as the
|
| // request is now processed.
|
| _subscription.resume();
|
| @@ -1879,7 +1883,21 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
|
| });
|
| }
|
|
|
| + void _startTimeout() {
|
| + assert(_state == _IDLE);
|
| + _stopTimeout();
|
| + if (_httpServer.idleTimeout == null) return;
|
| + _idleTimer = new Timer(_httpServer.idleTimeout, () {
|
| + destroy();
|
| + });
|
| + }
|
| +
|
| + void _stopTimeout() {
|
| + if (_idleTimer != null) _idleTimer.cancel();
|
| + }
|
| +
|
| void destroy() {
|
| + _stopTimeout();
|
| if (_state == _CLOSING || _state == _DETACHED) return;
|
| _state = _CLOSING;
|
| _socket.destroy();
|
| @@ -1887,6 +1905,7 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
|
| }
|
|
|
| Future<Socket> detachSocket() {
|
| + _stopTimeout();
|
| _state = _DETACHED;
|
| // Remove connection from server.
|
| _httpServer._connectionClosed(this);
|
| @@ -1911,6 +1930,8 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
|
| class _HttpServer extends Stream<HttpRequest> implements HttpServer {
|
| String serverHeader = _getHttpVersion();
|
|
|
| + Duration idleTimeout = const Duration(seconds: 120);
|
| +
|
| static Future<HttpServer> bind(address, int port, int backlog) {
|
| return ServerSocket.bind(address, port, backlog: backlog).then((socket) {
|
| return new _HttpServer._(socket, true);
|
|
|