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

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

Issue 124753002: Code cleanup (mostly io lib and some http lib). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 6 years, 11 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
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 /** 7 /**
8 * The [SecureServerSocket] is a server socket, providing a stream of high-level 8 * The [SecureServerSocket] is a server socket, providing a stream of high-level
9 * [Socket]s. 9 * [Socket]s.
10 * 10 *
11 * See [SecureSocket] for more info. 11 * See [SecureSocket] for more info.
12 */ 12 */
13 class SecureServerSocket extends Stream<SecureSocket> { 13 class SecureServerSocket extends Stream<SecureSocket> {
14 final RawSecureServerSocket _socket; 14 final RawSecureServerSocket _socket;
15 15
16 SecureServerSocket._(RawSecureServerSocket this._socket); 16 SecureServerSocket._(this._socket);
17 17
18 /** 18 /**
19 * Returns a future for a [SecureServerSocket]. When the future 19 * Returns a future for a [SecureServerSocket]. When the future
20 * completes the server socket is bound to the given [address] and 20 * completes the server socket is bound to the given [address] and
21 * [port] and has started listening on it. 21 * [port] and has started listening on it.
22 * 22 *
23 * The [address] can either be a [String] or an 23 * The [address] can either be a [String] or an
24 * [InternetAddress]. If [address] is a [String], [bind] will 24 * [InternetAddress]. If [address] is a [String], [bind] will
25 * perform a [InternetAddress.lookup] and use the first value in the 25 * perform a [InternetAddress.lookup] and use the first value in the
26 * list. To listen on the loopback adapter, which will allow only 26 * list. To listen on the loopback adapter, which will allow only
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class RawSecureServerSocket extends Stream<RawSecureSocket> { 116 class RawSecureServerSocket extends Stream<RawSecureSocket> {
117 RawServerSocket _socket; 117 RawServerSocket _socket;
118 StreamController<RawSecureSocket> _controller; 118 StreamController<RawSecureSocket> _controller;
119 StreamSubscription<RawSocket> _subscription; 119 StreamSubscription<RawSocket> _subscription;
120 final String certificateName; 120 final String certificateName;
121 final bool requestClientCertificate; 121 final bool requestClientCertificate;
122 final bool requireClientCertificate; 122 final bool requireClientCertificate;
123 bool _closed = false; 123 bool _closed = false;
124 124
125 RawSecureServerSocket._(RawServerSocket serverSocket, 125 RawSecureServerSocket._(RawServerSocket serverSocket,
126 String this.certificateName, 126 this.certificateName,
127 bool this.requestClientCertificate, 127 this.requestClientCertificate,
128 bool this.requireClientCertificate) { 128 this.requireClientCertificate) {
129 _socket = serverSocket; 129 _socket = serverSocket;
130 _controller = new StreamController<RawSecureSocket>( 130 _controller = new StreamController<RawSecureSocket>(
131 sync: true, 131 sync: true,
132 onListen: _onSubscriptionStateChange, 132 onListen: _onSubscriptionStateChange,
133 onPause: _onPauseStateChange, 133 onPause: _onPauseStateChange,
134 onResume: _onPauseStateChange, 134 onResume: _onPauseStateChange,
135 onCancel: _onSubscriptionStateChange); 135 onCancel: _onSubscriptionStateChange);
136 } 136 }
137 137
138 /** 138 /**
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } else { 246 } else {
247 _controller.add(secureConnection); 247 _controller.add(secureConnection);
248 } 248 }
249 }).catchError((e) { 249 }).catchError((e) {
250 if (!_closed) { 250 if (!_closed) {
251 _controller.addError(e); 251 _controller.addError(e);
252 } 252 }
253 }); 253 });
254 } 254 }
255 255
256 void _onError(e, [StackTrace stackTrace]) { 256 void _onError(e, [StackTrace stackTrace]) =>
257 _controller.addError(e, stackTrace); 257 _controller.addError(e, stackTrace);
258 }
259 258
260 void _onDone() { 259 void _onDone() => _controller.close();
261 _controller.close();
262 }
263 260
264 void _onPauseStateChange() { 261 void _onPauseStateChange() {
265 if (_controller.isPaused) { 262 if (_controller.isPaused) {
266 _subscription.pause(); 263 _subscription.pause();
267 } else { 264 } else {
268 _subscription.resume(); 265 _subscription.resume();
269 } 266 }
270 } 267 }
271 268
272 void _onSubscriptionStateChange() { 269 void _onSubscriptionStateChange() {
273 if (_controller.hasListener) { 270 if (_controller.hasListener) {
274 _subscription = _socket.listen(_onData, 271 _subscription = _socket.listen(_onData,
275 onDone: _onDone, 272 onDone: _onDone,
276 onError: _onError); 273 onError: _onError);
277 } else { 274 } else {
278 close(); 275 close();
279 } 276 }
280 } 277 }
281 } 278 }
282 279
283 280
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698