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

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

Issue 169383003: Make event-handlers edge-triggered and move socket-state to Dart. (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 | « runtime/bin/socket_patch.dart ('k') | sdk/lib/io/websocket_impl.dart » ('j') | 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 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 _pauseCount == 0 && 966 _pauseCount == 0 &&
967 _secureFilter != null && 967 _secureFilter != null &&
968 !_secureFilter.buffers[READ_PLAINTEXT].isEmpty) { 968 !_secureFilter.buffers[READ_PLAINTEXT].isEmpty) {
969 _pendingReadEvent = true; 969 _pendingReadEvent = true;
970 Timer.run(_sendReadEvent); 970 Timer.run(_sendReadEvent);
971 } 971 }
972 } 972 }
973 973
974 _sendReadEvent() { 974 _sendReadEvent() {
975 _pendingReadEvent = false; 975 _pendingReadEvent = false;
976 if (_readEventsEnabled && 976 if (_status != CLOSED &&
977 _readEventsEnabled &&
977 _pauseCount == 0 && 978 _pauseCount == 0 &&
978 _secureFilter != null && 979 _secureFilter != null &&
979 !_secureFilter.buffers[READ_PLAINTEXT].isEmpty) { 980 !_secureFilter.buffers[READ_PLAINTEXT].isEmpty) {
980 _controller.add(RawSocketEvent.READ); 981 _controller.add(RawSocketEvent.READ);
981 _scheduleReadEvent(); 982 _scheduleReadEvent();
982 } 983 }
983 } 984 }
984 985
985 // If a write event should be sent, add it to the controller. 986 // If a write event should be sent, add it to the controller.
986 _sendWriteEvent() { 987 _sendWriteEvent() {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 written += toWrite; 1158 written += toWrite;
1158 toWrite = min(bytes - written, linearFree); 1159 toWrite = min(bytes - written, linearFree);
1159 } 1160 }
1160 return written; 1161 return written;
1161 } 1162 }
1162 1163
1163 int writeFromSource(List<int> getData(int requested)) { 1164 int writeFromSource(List<int> getData(int requested)) {
1164 int written = 0; 1165 int written = 0;
1165 int toWrite = linearFree; 1166 int toWrite = linearFree;
1166 // Loop over zero, one, or two linear data ranges. 1167 // Loop over zero, one, or two linear data ranges.
1167 while (toWrite > 0) { 1168 do {
1168 // Source returns at most toWrite bytes, and it returns null when empty. 1169 // Source returns at most toWrite bytes, and it returns null when empty.
1169 var inputData = getData(toWrite); 1170 var inputData = getData(toWrite);
1170 if (inputData == null) break; 1171 if (inputData == null || inputData.length == 0) break;
1171 var len = inputData.length; 1172 var len = inputData.length;
1172 data.setRange(end, end + len, inputData); 1173 data.setRange(end, end + len, inputData);
1173 advanceEnd(len); 1174 advanceEnd(len);
1174 written += len; 1175 written += len;
1175 toWrite = linearFree; 1176 toWrite = linearFree;
1176 } 1177 } while (toWrite > 0);
1177 return written; 1178 return written;
1178 } 1179 }
1179 1180
1180 bool readToSocket(RawSocket socket) { 1181 bool readToSocket(RawSocket socket) {
1181 // Loop over zero, one, or two linear data ranges. 1182 // Loop over zero, one, or two linear data ranges.
1182 while (true) { 1183 while (true) {
1183 var toWrite = linearLength; 1184 var toWrite = linearLength;
1184 if (toWrite == 0) return false; 1185 if (toWrite == 0) return false;
1185 int bytes = socket.write(data, start, toWrite); 1186 int bytes = socket.write(data, start, toWrite);
1186 advanceStart(bytes); 1187 advanceStart(bytes);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 /** 1265 /**
1265 * An exception that happens in the handshake phase of establishing 1266 * An exception that happens in the handshake phase of establishing
1266 * a secure network connection, when looking up or verifying a 1267 * a secure network connection, when looking up or verifying a
1267 * certificate. 1268 * certificate.
1268 */ 1269 */
1269 class CertificateException extends TlsException { 1270 class CertificateException extends TlsException {
1270 const CertificateException([String message = "", 1271 const CertificateException([String message = "",
1271 OSError osError = null]) 1272 OSError osError = null])
1272 : super._("CertificateException", message, osError); 1273 : super._("CertificateException", message, osError);
1273 } 1274 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | sdk/lib/io/websocket_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698