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

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

Issue 170843010: Fix secure socket filter after edge-triggering. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | « no previous file | 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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 _filterActive = true; 888 _filterActive = true;
889 _filterPending = false; 889 _filterPending = false;
890 _pushAllFilterStages().then((status) { 890 _pushAllFilterStages().then((status) {
891 _filterStatus = status; 891 _filterStatus = status;
892 _filterActive = false; 892 _filterActive = false;
893 if (_status == CLOSED) { 893 if (_status == CLOSED) {
894 _secureFilter.destroy(); 894 _secureFilter.destroy();
895 _secureFilter = null; 895 _secureFilter = null;
896 return; 896 return;
897 } 897 }
898 _socket.readEventsEnabled = true;
898 if (_filterStatus.writeEmpty && _closedWrite && !_socketClosedWrite) { 899 if (_filterStatus.writeEmpty && _closedWrite && !_socketClosedWrite) {
899 // Checks for and handles all cases of partially closed sockets. 900 // Checks for and handles all cases of partially closed sockets.
900 shutdown(SocketDirection.SEND); 901 shutdown(SocketDirection.SEND);
901 if (_status == CLOSED) return; 902 if (_status == CLOSED) return;
902 } 903 }
903 if (_filterStatus.readEmpty && _socketClosedRead && !_closedRead) { 904 if (_filterStatus.readEmpty && _socketClosedRead && !_closedRead) {
904 if (_status == HANDSHAKE) { 905 if (_status == HANDSHAKE) {
905 _secureFilter.handshake(); 906 _secureFilter.handshake();
906 if (_status == HANDSHAKE) { 907 if (_status == HANDSHAKE) {
907 throw new HandshakeException( 908 throw new HandshakeException(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } else { 942 } else {
942 return null; 943 return null;
943 } 944 }
944 } 945 }
945 946
946 void _readSocket() { 947 void _readSocket() {
947 if (_status == CLOSED) return; 948 if (_status == CLOSED) return;
948 var buffer = _secureFilter.buffers[READ_ENCRYPTED]; 949 var buffer = _secureFilter.buffers[READ_ENCRYPTED];
949 if (buffer.writeFromSource(_readSocketOrBufferedData) > 0) { 950 if (buffer.writeFromSource(_readSocketOrBufferedData) > 0) {
950 _filterStatus.readEmpty = false; 951 _filterStatus.readEmpty = false;
952 } else {
953 _socket.readEventsEnabled = false;
951 } 954 }
952 } 955 }
953 956
954 void _writeSocket() { 957 void _writeSocket() {
955 if (_socketClosedWrite) return; 958 if (_socketClosedWrite) return;
956 var buffer = _secureFilter.buffers[WRITE_ENCRYPTED]; 959 var buffer = _secureFilter.buffers[WRITE_ENCRYPTED];
957 if (buffer.readToSocket(_socket)) { // Returns true if blocked 960 if (buffer.readToSocket(_socket)) { // Returns true if blocked
958 _socket.writeEventsEnabled = true; 961 _socket.writeEventsEnabled = true;
959 } 962 }
960 } 963 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 written += toWrite; 1161 written += toWrite;
1159 toWrite = min(bytes - written, linearFree); 1162 toWrite = min(bytes - written, linearFree);
1160 } 1163 }
1161 return written; 1164 return written;
1162 } 1165 }
1163 1166
1164 int writeFromSource(List<int> getData(int requested)) { 1167 int writeFromSource(List<int> getData(int requested)) {
1165 int written = 0; 1168 int written = 0;
1166 int toWrite = linearFree; 1169 int toWrite = linearFree;
1167 // Loop over zero, one, or two linear data ranges. 1170 // Loop over zero, one, or two linear data ranges.
1168 do { 1171 while (toWrite > 0) {
1169 // Source returns at most toWrite bytes, and it returns null when empty. 1172 // Source returns at most toWrite bytes, and it returns null when empty.
1170 var inputData = getData(toWrite); 1173 var inputData = getData(toWrite);
1171 if (inputData == null || inputData.length == 0) break; 1174 if (inputData == null || inputData.length == 0) break;
1172 var len = inputData.length; 1175 var len = inputData.length;
1173 data.setRange(end, end + len, inputData); 1176 data.setRange(end, end + len, inputData);
1174 advanceEnd(len); 1177 advanceEnd(len);
1175 written += len; 1178 written += len;
1176 toWrite = linearFree; 1179 toWrite = linearFree;
1177 } while (toWrite > 0); 1180 }
1178 return written; 1181 return written;
1179 } 1182 }
1180 1183
1181 bool readToSocket(RawSocket socket) { 1184 bool readToSocket(RawSocket socket) {
1182 // Loop over zero, one, or two linear data ranges. 1185 // Loop over zero, one, or two linear data ranges.
1183 while (true) { 1186 while (true) {
1184 var toWrite = linearLength; 1187 var toWrite = linearLength;
1185 if (toWrite == 0) return false; 1188 if (toWrite == 0) return false;
1186 int bytes = socket.write(data, start, toWrite); 1189 int bytes = socket.write(data, start, toWrite);
1187 advanceStart(bytes); 1190 advanceStart(bytes);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 /** 1268 /**
1266 * An exception that happens in the handshake phase of establishing 1269 * An exception that happens in the handshake phase of establishing
1267 * a secure network connection, when looking up or verifying a 1270 * a secure network connection, when looking up or verifying a
1268 * certificate. 1271 * certificate.
1269 */ 1272 */
1270 class CertificateException extends TlsException { 1273 class CertificateException extends TlsException {
1271 const CertificateException([String message = "", 1274 const CertificateException([String message = "",
1272 OSError osError = null]) 1275 OSError osError = null])
1273 : super._("CertificateException", message, osError); 1276 : super._("CertificateException", message, osError);
1274 } 1277 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698