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

Side by Side Diff: sdk/lib/io/http_session.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/http_impl.dart ('k') | sdk/lib/io/list_stream_impl.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 const String _DART_SESSION_ID = "DARTSESSID"; 7 const String _DART_SESSION_ID = "DARTSESSID";
8 8
9 // A _HttpSession is a node in a double-linked list, with _next and _prev being 9 // A _HttpSession is a node in a double-linked list, with _next and _prev being
10 // the previous and next pointers. 10 // the previous and next pointers.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 _head = session._next; 118 _head = session._next;
119 _stopTimer(); 119 _stopTimer();
120 _startTimer(); 120 _startTimer();
121 } 121 }
122 if (_tail == session) { 122 if (_tail == session) {
123 _tail = session._prev; 123 _tail = session._prev;
124 } 124 }
125 session._next = session._prev = null; 125 session._next = session._prev = null;
126 } 126 }
127 127
128 void _timerTimeout(_) { 128 void _timerTimeout() {
129 _stopTimer(); // Clear timer. 129 _stopTimer(); // Clear timer.
130 assert(_head != null); 130 assert(_head != null);
131 var session = _head; 131 var session = _head;
132 session.destroy(); // Will remove the session from timeout queue and map. 132 session.destroy(); // Will remove the session from timeout queue and map.
133 if (session._timeoutCallback != null) { 133 if (session._timeoutCallback != null) {
134 session._timeoutCallback(); 134 session._timeoutCallback();
135 } 135 }
136 } 136 }
137 137
138 void _startTimer() { 138 void _startTimer() {
139 assert(_timer == null); 139 assert(_timer == null);
140 if (_head != null) { 140 if (_head != null) {
141 int seconds = new DateTime.now().difference(_head.lastSeen).inSeconds; 141 int seconds = new DateTime.now().difference(_head.lastSeen).inSeconds;
142 _timer = new Timer((_sessionTimeout - seconds) * 1000, _timerTimeout); 142 _timer = new Timer(new Duration(seconds: _sessionTimeout - seconds),
143 _timerTimeout);
143 } 144 }
144 } 145 }
145 146
146 void _stopTimer() { 147 void _stopTimer() {
147 if (_timer != null) { 148 if (_timer != null) {
148 _timer.cancel(); 149 _timer.cancel();
149 _timer = null; 150 _timer = null;
150 } 151 }
151 } 152 }
152 153
153 Map<String, _HttpSession> _sessions; 154 Map<String, _HttpSession> _sessions;
154 int _sessionTimeout = 20 * 60; // 20 mins. 155 int _sessionTimeout = 20 * 60; // 20 mins.
155 _HttpSession _head; 156 _HttpSession _head;
156 _HttpSession _tail; 157 _HttpSession _tail;
157 Timer _timer; 158 Timer _timer;
158 159
159 external static Uint8List _getRandomBytes(int count); 160 external static Uint8List _getRandomBytes(int count);
160 } 161 }
161 162
OLDNEW
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | sdk/lib/io/list_stream_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698