OLD | NEW |
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 /** | 7 /** |
8 * A high-level class for communicating securely over a TCP socket, using | 8 * A high-level class for communicating securely over a TCP socket, using |
9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an | 9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an |
10 * [IOSink] interface, making it ideal for using together with | 10 * [IOSink] interface, making it ideal for using together with |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 432 |
433 var _status = HANDSHAKE; | 433 var _status = HANDSHAKE; |
434 bool _writeEventsEnabled = true; | 434 bool _writeEventsEnabled = true; |
435 bool _readEventsEnabled = true; | 435 bool _readEventsEnabled = true; |
436 int _pauseCount = 0; | 436 int _pauseCount = 0; |
437 bool _pendingReadEvent = false; | 437 bool _pendingReadEvent = false; |
438 bool _socketClosedRead = false; // The network socket is closed for reading. | 438 bool _socketClosedRead = false; // The network socket is closed for reading. |
439 bool _socketClosedWrite = false; // The network socket is closed for writing. | 439 bool _socketClosedWrite = false; // The network socket is closed for writing. |
440 bool _closedRead = false; // The secure socket has fired an onClosed event. | 440 bool _closedRead = false; // The secure socket has fired an onClosed event. |
441 bool _closedWrite = false; // The secure socket has been closed for writing. | 441 bool _closedWrite = false; // The secure socket has been closed for writing. |
| 442 Completer _closeCompleter = new Completer(); // The network socket is gone. |
442 _FilterStatus _filterStatus = new _FilterStatus(); | 443 _FilterStatus _filterStatus = new _FilterStatus(); |
443 bool _connectPending = false; | 444 bool _connectPending = false; |
444 bool _filterPending = false; | 445 bool _filterPending = false; |
445 bool _filterActive = false; | 446 bool _filterActive = false; |
446 | 447 |
447 _SecureFilter _secureFilter = new _SecureFilter(); | 448 _SecureFilter _secureFilter = new _SecureFilter(); |
448 int _filterPointer; | 449 int _filterPointer; |
449 SendPort _filterService; | 450 SendPort _filterService; |
450 | 451 |
451 static Future<_RawSecureSocket> connect( | 452 static Future<_RawSecureSocket> connect( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 607 |
607 String get remoteHost => _socket.remoteHost; | 608 String get remoteHost => _socket.remoteHost; |
608 | 609 |
609 int get remotePort => _socket.remotePort; | 610 int get remotePort => _socket.remotePort; |
610 | 611 |
611 int available() { | 612 int available() { |
612 if (_status != CONNECTED) return 0; | 613 if (_status != CONNECTED) return 0; |
613 return _secureFilter.buffers[READ_PLAINTEXT].length; | 614 return _secureFilter.buffers[READ_PLAINTEXT].length; |
614 } | 615 } |
615 | 616 |
616 void close() { | 617 Future<RawSecureSocket> close() { |
617 shutdown(SocketDirection.BOTH); | 618 shutdown(SocketDirection.BOTH); |
| 619 return _closeCompleter.future; |
| 620 } |
| 621 |
| 622 void _completeCloseCompleter([dummy]) { |
| 623 if (!_closeCompleter.isCompleted) _closeCompleter.complete(this); |
618 } | 624 } |
619 | 625 |
620 void _close() { | 626 void _close() { |
621 _closedWrite = true; | 627 _closedWrite = true; |
622 _closedRead = true; | 628 _closedRead = true; |
623 if (_socket != null) { | 629 if (_socket != null) { |
624 _socket.close(); | 630 _socket.close().then(_completeCloseCompleter); |
| 631 } else { |
| 632 _completeCloseCompleter(); |
625 } | 633 } |
626 _socketClosedWrite = true; | 634 _socketClosedWrite = true; |
627 _socketClosedRead = true; | 635 _socketClosedRead = true; |
628 if (!_filterActive && _secureFilter != null) { | 636 if (!_filterActive && _secureFilter != null) { |
629 _secureFilter.destroy(); | 637 _secureFilter.destroy(); |
630 _secureFilter = null; | 638 _secureFilter = null; |
631 } | 639 } |
632 if (_socketSubscription != null) { | 640 if (_socketSubscription != null) { |
633 _socketSubscription.cancel(); | 641 _socketSubscription.cancel(); |
634 } | 642 } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 /** | 1263 /** |
1256 * An exception that happens in the handshake phase of establishing | 1264 * An exception that happens in the handshake phase of establishing |
1257 * a secure network connection, when looking up or verifying a | 1265 * a secure network connection, when looking up or verifying a |
1258 * certificate. | 1266 * certificate. |
1259 */ | 1267 */ |
1260 class CertificateException extends TlsException { | 1268 class CertificateException extends TlsException { |
1261 const CertificateException([String message = "", | 1269 const CertificateException([String message = "", |
1262 OSError osError = null]) | 1270 OSError osError = null]) |
1263 : super._("CertificateException", message, osError); | 1271 : super._("CertificateException", message, osError); |
1264 } | 1272 } |
OLD | NEW |