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

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

Issue 1842703003: Fixes handling of short reads/writes for Mac SSL (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 8 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
« no previous file with comments | « runtime/bin/secure_socket_macos.cc ('k') | no next file » | 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 /** 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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 // TODO(ajohnsen): Do something here? 835 // TODO(ajohnsen): Do something here?
836 } 836 }
837 } 837 }
838 838
839 void _scheduleFilter() { 839 void _scheduleFilter() {
840 _filterPending = true; 840 _filterPending = true;
841 _tryFilter(); 841 _tryFilter();
842 } 842 }
843 843
844 void _tryFilter() { 844 void _tryFilter() {
845 if (_status == CLOSED) return; 845 if (_status == CLOSED) {
846 return;
847 }
846 if (_filterPending && !_filterActive) { 848 if (_filterPending && !_filterActive) {
847 _filterActive = true; 849 _filterActive = true;
848 _filterPending = false; 850 _filterPending = false;
849 _pushAllFilterStages().then((status) { 851 _pushAllFilterStages().then((status) {
850 _filterStatus = status; 852 _filterStatus = status;
851 _filterActive = false; 853 _filterActive = false;
852 if (_status == CLOSED) { 854 if (_status == CLOSED) {
853 _secureFilter.destroy(); 855 _secureFilter.destroy();
854 _secureFilter = null; 856 _secureFilter = null;
855 return; 857 return;
856 } 858 }
857 _socket.readEventsEnabled = true; 859 _socket.readEventsEnabled = true;
858 if (_filterStatus.writeEmpty && _closedWrite && !_socketClosedWrite) { 860 if (_filterStatus.writeEmpty && _closedWrite && !_socketClosedWrite) {
859 // Checks for and handles all cases of partially closed sockets. 861 // Checks for and handles all cases of partially closed sockets.
860 shutdown(SocketDirection.SEND); 862 shutdown(SocketDirection.SEND);
861 if (_status == CLOSED) return; 863 if (_status == CLOSED) {
864 return;
865 }
862 } 866 }
863 if (_filterStatus.readEmpty && _socketClosedRead && !_closedRead) { 867 if (_filterStatus.readEmpty && _socketClosedRead && !_closedRead) {
864 if (_status == HANDSHAKE) { 868 if (_status == HANDSHAKE) {
865 _secureFilter.handshake(); 869 _secureFilter.handshake();
866 if (_status == HANDSHAKE) { 870 if (_status == HANDSHAKE) {
867 throw new HandshakeException( 871 throw new HandshakeException(
868 'Connection terminated during handshake'); 872 'Connection terminated during handshake');
869 } 873 }
870 } 874 }
871 _closeHandler(); 875 _closeHandler();
872 } 876 }
873 if (_status == CLOSED) return; 877 if (_status == CLOSED) {
878 return;
879 }
874 if (_filterStatus.progress) { 880 if (_filterStatus.progress) {
875 _filterPending = true; 881 _filterPending = true;
876 if (_filterStatus.writePlaintextNoLongerFull) _sendWriteEvent(); 882 if (_filterStatus.writeEncryptedNoLongerEmpty) {
877 if (_filterStatus.readEncryptedNoLongerFull) _readSocket(); 883 _writeSocket();
878 if (_filterStatus.writeEncryptedNoLongerEmpty) _writeSocket(); 884 }
879 if (_filterStatus.readPlaintextNoLongerEmpty) _scheduleReadEvent(); 885 if (_filterStatus.writePlaintextNoLongerFull) {
880 if (_status == HANDSHAKE) _secureHandshake(); 886 _sendWriteEvent();
887 }
888 if (_filterStatus.readEncryptedNoLongerFull) {
889 _readSocket();
890 }
891 if (_filterStatus.readPlaintextNoLongerEmpty) {
892 _scheduleReadEvent();
893 }
894 if (_status == HANDSHAKE) {
895 _secureHandshake();
896 }
881 } 897 }
882 _tryFilter(); 898 _tryFilter();
883 }).catchError(_reportError); 899 }).catchError(_reportError);
884 } 900 }
885 } 901 }
886 902
887 List<int> _readSocketOrBufferedData(int bytes) { 903 List<int> _readSocketOrBufferedData(int bytes) {
888 if (_bufferedData != null) { 904 if (_bufferedData != null) {
889 if (bytes > _bufferedData.length - _bufferedDataIndex) { 905 if (bytes > _bufferedData.length - _bufferedDataIndex) {
890 bytes = _bufferedData.length - _bufferedDataIndex; 906 bytes = _bufferedData.length - _bufferedDataIndex;
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 /** 1250 /**
1235 * An exception that happens in the handshake phase of establishing 1251 * An exception that happens in the handshake phase of establishing
1236 * a secure network connection, when looking up or verifying a 1252 * a secure network connection, when looking up or verifying a
1237 * certificate. 1253 * certificate.
1238 */ 1254 */
1239 class CertificateException extends TlsException { 1255 class CertificateException extends TlsException {
1240 const CertificateException([String message = "", 1256 const CertificateException([String message = "",
1241 OSError osError = null]) 1257 OSError osError = null])
1242 : super._("CertificateException", message, osError); 1258 : super._("CertificateException", message, osError);
1243 } 1259 }
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698