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

Side by Side Diff: sdk/lib/io/http_impl.dart

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | sdk/lib/io/http_session.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 // The close queue handles graceful closing of HTTP connections. When 7 // The close queue handles graceful closing of HTTP connections. When
8 // a connection is added to the queue it will enter a wait state 8 // a connection is added to the queue it will enter a wait state
9 // waiting for all data written and possibly socket shutdown from 9 // waiting for all data written and possibly socket shutdown from
10 // peer. 10 // peer.
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 void _streamClose() { 495 void _streamClose() {
496 _ensureHeadersSent(); 496 _ensureHeadersSent();
497 _state = _HttpRequestResponseBase.DONE; 497 _state = _HttpRequestResponseBase.DONE;
498 // Stop tracking no pending write events. 498 // Stop tracking no pending write events.
499 _httpConnection._onNoPendingWrites = null; 499 _httpConnection._onNoPendingWrites = null;
500 // Ensure that any trailing data is written. 500 // Ensure that any trailing data is written.
501 _writeDone(); 501 _writeDone();
502 // Indicate to the connection that the response handling is done. 502 // Indicate to the connection that the response handling is done.
503 _httpConnection._responseClosed(); 503 _httpConnection._responseClosed();
504 if (_streamClosedHandler != null) { 504 if (_streamClosedHandler != null) {
505 new Timer(0, (_) => _streamClosedHandler()); 505 Timer.run(_streamClosedHandler);
506 } 506 }
507 } 507 }
508 508
509 void _streamSetNoPendingWriteHandler(callback()) { 509 void _streamSetNoPendingWriteHandler(callback()) {
510 if (_state != _HttpRequestResponseBase.DONE) { 510 if (_state != _HttpRequestResponseBase.DONE) {
511 _httpConnection._onNoPendingWrites = callback; 511 _httpConnection._onNoPendingWrites = callback;
512 } 512 }
513 } 513 }
514 514
515 void _streamSetClosedHandler(callback()) { 515 void _streamSetClosedHandler(callback()) {
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 1206
1207 void _streamClose() { 1207 void _streamClose() {
1208 _ensureHeadersSent(); 1208 _ensureHeadersSent();
1209 _state = _HttpRequestResponseBase.DONE; 1209 _state = _HttpRequestResponseBase.DONE;
1210 // Stop tracking no pending write events. 1210 // Stop tracking no pending write events.
1211 _httpConnection._onNoPendingWrites = null; 1211 _httpConnection._onNoPendingWrites = null;
1212 // Ensure that any trailing data is written. 1212 // Ensure that any trailing data is written.
1213 _writeDone(); 1213 _writeDone();
1214 _connection._requestClosed(); 1214 _connection._requestClosed();
1215 if (_streamClosedHandler != null) { 1215 if (_streamClosedHandler != null) {
1216 new Timer(0, (_) => _streamClosedHandler()); 1216 Timer.run(_streamClosedHandler);
1217 } 1217 }
1218 } 1218 }
1219 1219
1220 void _streamSetNoPendingWriteHandler(callback()) { 1220 void _streamSetNoPendingWriteHandler(callback()) {
1221 if (_state != _HttpRequestResponseBase.DONE) { 1221 if (_state != _HttpRequestResponseBase.DONE) {
1222 _httpConnection._onNoPendingWrites = callback; 1222 _httpConnection._onNoPendingWrites = callback;
1223 } 1223 }
1224 } 1224 }
1225 1225
1226 void _streamSetClosedHandler(callback()) { 1226 void _streamSetClosedHandler(callback()) {
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 socket.onError = null; 2049 socket.onError = null;
2050 _SocketConnection socketConn = 2050 _SocketConnection socketConn =
2051 new _SocketConnection(connectHost, connectPort, socket); 2051 new _SocketConnection(connectHost, connectPort, socket);
2052 _activeSockets.add(socketConn); 2052 _activeSockets.add(socketConn);
2053 _connectionOpened(socketConn, connection, !proxy.isDirect); 2053 _connectionOpened(socketConn, connection, !proxy.isDirect);
2054 }; 2054 };
2055 } else { 2055 } else {
2056 _SocketConnection socketConn = socketConnections.removeFirst(); 2056 _SocketConnection socketConn = socketConnections.removeFirst();
2057 socketConn._markRetrieved(); 2057 socketConn._markRetrieved();
2058 _activeSockets.add(socketConn); 2058 _activeSockets.add(socketConn);
2059 new Timer(0, (ignored) => 2059 Timer.run(() =>
2060 _connectionOpened(socketConn, connection, !proxy.isDirect)); 2060 _connectionOpened(socketConn, connection, !proxy.isDirect));
2061 2061
2062 // Get rid of eviction timer if there are no more active connections. 2062 // Get rid of eviction timer if there are no more active connections.
2063 if (socketConnections.isEmpty) _openSockets.remove(key); 2063 if (socketConnections.isEmpty) _openSockets.remove(key);
2064 if (_openSockets.isEmpty) _cancelEvictionTimer(); 2064 if (_openSockets.isEmpty) _cancelEvictionTimer();
2065 } 2065 }
2066 } 2066 }
2067 2067
2068 // Find out if we want a secure socket. 2068 // Find out if we want a secure socket.
2069 bool is_secure = (url.scheme == "https"); 2069 bool is_secure = (url.scheme == "https");
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 } 2144 }
2145 } 2145 }
2146 }); 2146 });
2147 2147
2148 // Remove the keys for which here are no more open connections. 2148 // Remove the keys for which here are no more open connections.
2149 emptyKeys.forEach((String key) => _openSockets.remove(key)); 2149 emptyKeys.forEach((String key) => _openSockets.remove(key));
2150 2150
2151 // If all connections where evicted cancel the eviction timer. 2151 // If all connections where evicted cancel the eviction timer.
2152 if (_openSockets.isEmpty) _cancelEvictionTimer(); 2152 if (_openSockets.isEmpty) _cancelEvictionTimer();
2153 } 2153 }
2154 _evictionTimer = new Timer.repeating(10000, _handleEviction); 2154 _evictionTimer = new Timer.repeating(const Duration(seconds: 10),
2155 _handleEviction);
2155 } 2156 }
2156 2157
2157 // Return connection. 2158 // Return connection.
2158 _activeSockets.remove(socketConn); 2159 _activeSockets.remove(socketConn);
2159 sockets.addFirst(socketConn); 2160 sockets.addFirst(socketConn);
2160 } 2161 }
2161 2162
2162 void _closeSocketConnection(_SocketConnection socketConn) { 2163 void _closeSocketConnection(_SocketConnection socketConn) {
2163 socketConn._close(); 2164 socketConn._close();
2164 _activeSockets.remove(socketConn); 2165 _activeSockets.remove(socketConn);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 2324
2324 2325
2325 class _RedirectInfo implements RedirectInfo { 2326 class _RedirectInfo implements RedirectInfo {
2326 const _RedirectInfo(int this.statusCode, 2327 const _RedirectInfo(int this.statusCode,
2327 String this.method, 2328 String this.method,
2328 Uri this.location); 2329 Uri this.location);
2329 final int statusCode; 2330 final int statusCode;
2330 final String method; 2331 final String method;
2331 final Uri location; 2332 final Uri location;
2332 } 2333 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | sdk/lib/io/http_session.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698