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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 if (_socketClosedWrite) { | 384 if (_socketClosedWrite) { |
385 _close(); | 385 _close(); |
386 } | 386 } |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 bool get writeEventsEnabled => _writeEventsEnabled; | 390 bool get writeEventsEnabled => _writeEventsEnabled; |
391 | 391 |
392 void set writeEventsEnabled(bool value) { | 392 void set writeEventsEnabled(bool value) { |
393 if (value && | 393 if (value && |
394 _controller.hasSubscribers && | 394 _controller.hasListener && |
395 _secureFilter != null && | 395 _secureFilter != null && |
396 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { | 396 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { |
397 Timer.run(() => _controller.add(RawSocketEvent.WRITE)); | 397 Timer.run(() => _controller.add(RawSocketEvent.WRITE)); |
398 } else { | 398 } else { |
399 _writeEventsEnabled = value; | 399 _writeEventsEnabled = value; |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 bool get readEventsEnabled => _readEventsEnabled; | 403 bool get readEventsEnabled => _readEventsEnabled; |
404 | 404 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 if (_filterWriteEmpty && _closedWrite && !_socketClosedWrite) { | 494 if (_filterWriteEmpty && _closedWrite && !_socketClosedWrite) { |
495 // Close _socket for write, by calling shutdown(), to avoid cloning the | 495 // Close _socket for write, by calling shutdown(), to avoid cloning the |
496 // socket closing code in shutdown(). | 496 // socket closing code in shutdown(). |
497 shutdown(SocketDirection.SEND); | 497 shutdown(SocketDirection.SEND); |
498 } | 498 } |
499 if (_status == HANDSHAKE) { | 499 if (_status == HANDSHAKE) { |
500 try { | 500 try { |
501 _secureHandshake(); | 501 _secureHandshake(); |
502 } catch (e) { _reportError(e, "RawSecureSocket error"); } | 502 } catch (e) { _reportError(e, "RawSecureSocket error"); } |
503 } else if (_status == CONNECTED && | 503 } else if (_status == CONNECTED && |
504 _controller.hasSubscribers && | 504 _controller.hasListener && |
505 _writeEventsEnabled && | 505 _writeEventsEnabled && |
506 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { | 506 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { |
507 // Reset the one-shot handler. | 507 // Reset the one-shot handler. |
508 _writeEventsEnabled = false; | 508 _writeEventsEnabled = false; |
509 _controller.add(RawSocketEvent.WRITE); | 509 _controller.add(RawSocketEvent.WRITE); |
510 } | 510 } |
511 } | 511 } |
512 | 512 |
513 void _eventDispatcher(RawSocketEvent event) { | 513 void _eventDispatcher(RawSocketEvent event) { |
514 if (event == RawSocketEvent.READ) { | 514 if (event == RawSocketEvent.READ) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (!_socketClosedRead || !_socketClosedWrite) { | 621 if (!_socketClosedRead || !_socketClosedWrite) { |
622 if (_controller.isPaused) { | 622 if (_controller.isPaused) { |
623 _socketSubscription.pause(); | 623 _socketSubscription.pause(); |
624 } else { | 624 } else { |
625 _socketSubscription.resume(); | 625 _socketSubscription.resume(); |
626 } | 626 } |
627 } | 627 } |
628 } | 628 } |
629 | 629 |
630 void _onSubscriptionStateChange() { | 630 void _onSubscriptionStateChange() { |
631 if (_controller.hasSubscribers) { | 631 if (_controller.hasListener) { |
632 // TODO(ajohnsen): Do something here? | 632 // TODO(ajohnsen): Do something here? |
633 } | 633 } |
634 } | 634 } |
635 | 635 |
636 void _readEncryptedData() { | 636 void _readEncryptedData() { |
637 // Read from the socket, and push it through the filter as far as | 637 // Read from the socket, and push it through the filter as far as |
638 // possible. | 638 // possible. |
639 var encrypted = _secureFilter.buffers[READ_ENCRYPTED]; | 639 var encrypted = _secureFilter.buffers[READ_ENCRYPTED]; |
640 var plaintext = _secureFilter.buffers[READ_PLAINTEXT]; | 640 var plaintext = _secureFilter.buffers[READ_PLAINTEXT]; |
641 bool progress = true; | 641 bool progress = true; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 void destroy(); | 753 void destroy(); |
754 void handshake(); | 754 void handshake(); |
755 void init(); | 755 void init(); |
756 X509Certificate get peerCertificate; | 756 X509Certificate get peerCertificate; |
757 int processBuffer(int bufferIndex); | 757 int processBuffer(int bufferIndex); |
758 void registerBadCertificateCallback(Function callback); | 758 void registerBadCertificateCallback(Function callback); |
759 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); | 759 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); |
760 | 760 |
761 List<_ExternalBuffer> get buffers; | 761 List<_ExternalBuffer> get buffers; |
762 } | 762 } |
OLD | NEW |