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

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

Issue 13863012: Refactor List.setRange function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/mime_multipart_parser.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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // Write the data to the socket, and flush it as much as possible 462 // Write the data to the socket, and flush it as much as possible
463 // until it would block. If the write would block, _writeEncryptedData sets 463 // until it would block. If the write would block, _writeEncryptedData sets
464 // up handlers to flush the pipeline when possible. 464 // up handlers to flush the pipeline when possible.
465 int write(List<int> data, [int offset, int bytes]) { 465 int write(List<int> data, [int offset, int bytes]) {
466 if (_closedWrite) { 466 if (_closedWrite) {
467 _controller.addError(new AsyncError(new SocketIOException( 467 _controller.addError(new AsyncError(new SocketIOException(
468 "Writing to a closed socket"))); 468 "Writing to a closed socket")));
469 return 0; 469 return 0;
470 } 470 }
471 if (_status != CONNECTED) return 0; 471 if (_status != CONNECTED) return 0;
472
473 if (offset == null) offset = 0;
474 if (bytes == null) bytes = data.length - offset;
475
472 var buffer = _secureFilter.buffers[WRITE_PLAINTEXT]; 476 var buffer = _secureFilter.buffers[WRITE_PLAINTEXT];
473 if (bytes > buffer.free) { 477 if (bytes > buffer.free) {
474 bytes = buffer.free; 478 bytes = buffer.free;
475 } 479 }
476 if (bytes > 0) { 480 if (bytes > 0) {
477 buffer.data.setRange(buffer.start + buffer.length, bytes, data, offset); 481 int startIndex = buffer.start + buffer.length;
482 buffer.data.setRange(startIndex, startIndex + bytes, data, offset);
478 buffer.length += bytes; 483 buffer.length += bytes;
479 } 484 }
480 _writeEncryptedData(); // Tries to flush all pipeline stages. 485 _writeEncryptedData(); // Tries to flush all pipeline stages.
481 return bytes; 486 return bytes;
482 } 487 }
483 488
484 X509Certificate get peerCertificate => _secureFilter.peerCertificate; 489 X509Certificate get peerCertificate => _secureFilter.peerCertificate;
485 490
486 bool setOption(SocketOption option, bool enabled) { 491 bool setOption(SocketOption option, bool enabled) {
487 if (_socket == null) return false; 492 if (_socket == null) return false;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 int bytes = _secureFilter.processBuffer(READ_ENCRYPTED); 658 int bytes = _secureFilter.processBuffer(READ_ENCRYPTED);
654 if (bytes > 0) { 659 if (bytes > 0) {
655 encrypted.advanceStart(bytes); 660 encrypted.advanceStart(bytes);
656 progress = true; 661 progress = true;
657 } 662 }
658 } 663 }
659 if (!_socketClosedRead && encrypted.free > 0) { 664 if (!_socketClosedRead && encrypted.free > 0) {
660 List<int> data = _socket.read(encrypted.free); 665 List<int> data = _socket.read(encrypted.free);
661 if (data != null) { 666 if (data != null) {
662 int bytes = data.length; 667 int bytes = data.length;
663 encrypted.data.setRange(encrypted.start + encrypted.length, 668 int startIndex = encrypted.start + encrypted.length;
664 bytes, 669 encrypted.data.setRange(startIndex, startIndex + bytes, data);
665 data);
666 encrypted.length += bytes; 670 encrypted.length += bytes;
667 progress = true; 671 progress = true;
668 } 672 }
669 } 673 }
670 } 674 }
671 // If there is any data in any stages of the filter, there should 675 // If there is any data in any stages of the filter, there should
672 // be data in the plaintext buffer after this process. 676 // be data in the plaintext buffer after this process.
673 // TODO(whesse): Verify that this is true, and there can be no 677 // TODO(whesse): Verify that this is true, and there can be no
674 // partial encrypted block stuck in the secureFilter. 678 // partial encrypted block stuck in the secureFilter.
675 _filterReadEmpty = (plaintext.length == 0); 679 _filterReadEmpty = (plaintext.length == 0);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 void destroy(); 757 void destroy();
754 void handshake(); 758 void handshake();
755 void init(); 759 void init();
756 X509Certificate get peerCertificate; 760 X509Certificate get peerCertificate;
757 int processBuffer(int bufferIndex); 761 int processBuffer(int bufferIndex);
758 void registerBadCertificateCallback(Function callback); 762 void registerBadCertificateCallback(Function callback);
759 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); 763 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler);
760 764
761 List<_ExternalBuffer> get buffers; 765 List<_ExternalBuffer> get buffers;
762 } 766 }
OLDNEW
« no previous file with comments | « sdk/lib/io/mime_multipart_parser.dart ('k') | sdk/lib/io/websocket_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698