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

Side by Side Diff: runtime/bin/secure_socket.cc

Issue 11819062: Speed up secure sockets by increasing encrypted buffer size. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/secure_socket.h ('k') | sdk/lib/io/secure_socket.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "bin/secure_socket.h" 5 #include "bin/secure_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void SSLFilter::InitializeBuffers(Dart_Handle dart_this) { 280 void SSLFilter::InitializeBuffers(Dart_Handle dart_this) {
281 // Create SSLFilter buffers as ExternalUint8Array objects. 281 // Create SSLFilter buffers as ExternalUint8Array objects.
282 Dart_Handle dart_buffers_object = ThrowIfError( 282 Dart_Handle dart_buffers_object = ThrowIfError(
283 Dart_GetField(dart_this, DartUtils::NewString("buffers"))); 283 Dart_GetField(dart_this, DartUtils::NewString("buffers")));
284 Dart_Handle dart_buffer_object = 284 Dart_Handle dart_buffer_object =
285 Dart_ListGetAt(dart_buffers_object, kReadPlaintext); 285 Dart_ListGetAt(dart_buffers_object, kReadPlaintext);
286 Dart_Handle external_buffer_class = 286 Dart_Handle external_buffer_class =
287 Dart_InstanceGetClass(dart_buffer_object); 287 Dart_InstanceGetClass(dart_buffer_object);
288 Dart_Handle dart_buffer_size = ThrowIfError( 288 Dart_Handle dart_buffer_size = ThrowIfError(
289 Dart_GetField(external_buffer_class, DartUtils::NewString("SIZE"))); 289 Dart_GetField(external_buffer_class, DartUtils::NewString("SIZE")));
290 buffer_size_ = DartUtils::GetIntegerValue(dart_buffer_size); 290 int64_t buffer_size = DartUtils::GetIntegerValue(dart_buffer_size);
291 if (buffer_size_ <= 0 || buffer_size_ > 1024 * 1024) { 291 Dart_Handle dart_encrypted_buffer_size = ThrowIfError(
292 Dart_GetField(external_buffer_class,
293 DartUtils::NewString("ENCRYPTED_SIZE")));
294 int64_t encrypted_buffer_size =
295 DartUtils::GetIntegerValue(dart_encrypted_buffer_size);
296 if (buffer_size <= 0 || buffer_size > 1024 * 1024) {
292 Dart_ThrowException( 297 Dart_ThrowException(
293 DartUtils::NewString("Invalid buffer size in _ExternalBuffer")); 298 DartUtils::NewString("Invalid buffer size in _ExternalBuffer"));
294 } 299 }
300 if (encrypted_buffer_size <= 0 || encrypted_buffer_size > 1024 * 1024) {
301 Dart_ThrowException(DartUtils::NewString(
302 "Invalid encrypted buffer size in _ExternalBuffer"));
303 }
304 buffer_size_ = static_cast<int>(buffer_size);
305 encrypted_buffer_size_ = static_cast<int>(encrypted_buffer_size);
306
295 307
296 Dart_Handle data_identifier = DartUtils::NewString("data"); 308 Dart_Handle data_identifier = DartUtils::NewString("data");
297 for (int i = 0; i < kNumBuffers; ++i) { 309 for (int i = 0; i < kNumBuffers; ++i) {
310 int size = isEncrypted(i) ? encrypted_buffer_size_ : buffer_size_;
298 dart_buffer_objects_[i] = ThrowIfError( 311 dart_buffer_objects_[i] = ThrowIfError(
299 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i))); 312 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i)));
300 buffers_[i] = new uint8_t[buffer_size_]; 313 buffers_[i] = new uint8_t[size];
301 Dart_Handle data = ThrowIfError( 314 Dart_Handle data = ThrowIfError(
302 Dart_NewExternalByteArray(buffers_[i], buffer_size_, NULL, NULL)); 315 Dart_NewExternalByteArray(buffers_[i], size, NULL, NULL));
303 ThrowIfError(Dart_SetField(dart_buffer_objects_[i], 316 ThrowIfError(Dart_SetField(dart_buffer_objects_[i],
304 data_identifier, 317 data_identifier,
305 data)); 318 data));
306 } 319 }
307 } 320 }
308 321
309 322
310 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) { 323 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) {
311 ASSERT(NULL == handshake_complete_); 324 ASSERT(NULL == handshake_complete_);
312 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete)); 325 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete));
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 if (bad_certificate_callback_ != NULL) { 574 if (bad_certificate_callback_ != NULL) {
562 Dart_DeletePersistentHandle(bad_certificate_callback_); 575 Dart_DeletePersistentHandle(bad_certificate_callback_);
563 } 576 }
564 free(client_certificate_name_); 577 free(client_certificate_name_);
565 578
566 PR_Close(filter_); 579 PR_Close(filter_);
567 } 580 }
568 581
569 582
570 intptr_t SSLFilter::ProcessBuffer(int buffer_index) { 583 intptr_t SSLFilter::ProcessBuffer(int buffer_index) {
584 int size = isEncrypted(buffer_index) ? encrypted_buffer_size_ : buffer_size_;
571 Dart_Handle buffer_object = dart_buffer_objects_[buffer_index]; 585 Dart_Handle buffer_object = dart_buffer_objects_[buffer_index];
572 Dart_Handle start_object = ThrowIfError( 586 Dart_Handle start_object = ThrowIfError(
573 Dart_GetField(buffer_object, string_start_)); 587 Dart_GetField(buffer_object, string_start_));
574 Dart_Handle length_object = ThrowIfError( 588 Dart_Handle length_object = ThrowIfError(
575 Dart_GetField(buffer_object, string_length_)); 589 Dart_GetField(buffer_object, string_length_));
576 int64_t unsafe_start = DartUtils::GetIntegerValue(start_object); 590 int64_t unsafe_start = DartUtils::GetIntegerValue(start_object);
577 int64_t unsafe_length = DartUtils::GetIntegerValue(length_object); 591 int64_t unsafe_length = DartUtils::GetIntegerValue(length_object);
578 ASSERT(unsafe_start >= 0); 592 ASSERT(unsafe_start >= 0);
579 ASSERT(unsafe_start < buffer_size_); 593 ASSERT(unsafe_start < size);
580 ASSERT(unsafe_length >= 0); 594 ASSERT(unsafe_length >= 0);
581 ASSERT(unsafe_length <= buffer_size_); 595 ASSERT(unsafe_length <= size);
582 intptr_t start = static_cast<intptr_t>(unsafe_start); 596 int start = static_cast<int>(unsafe_start);
583 intptr_t length = static_cast<intptr_t>(unsafe_length); 597 int length = static_cast<int>(unsafe_length);
584 uint8_t* buffer = buffers_[buffer_index]; 598 uint8_t* buffer = buffers_[buffer_index];
585 599
586 int bytes_processed = 0; 600 int bytes_processed = 0;
587 switch (buffer_index) { 601 switch (buffer_index) {
588 case kReadPlaintext: { 602 case kReadPlaintext: {
589 int bytes_free = buffer_size_ - start - length; 603 int bytes_free = size - start - length;
590 bytes_processed = PR_Read(filter_, 604 bytes_processed = PR_Read(filter_,
591 buffer + start + length, 605 buffer + start + length,
592 bytes_free); 606 bytes_free);
593 if (bytes_processed < 0) { 607 if (bytes_processed < 0) {
594 ASSERT(bytes_processed == -1); 608 ASSERT(bytes_processed == -1);
595 // TODO(whesse): Handle unexpected errors here. 609 // TODO(whesse): Handle unexpected errors here.
596 PRErrorCode pr_error = PR_GetError(); 610 PRErrorCode pr_error = PR_GetError();
597 if (PR_WOULD_BLOCK_ERROR != pr_error) { 611 if (PR_WOULD_BLOCK_ERROR != pr_error) {
598 ThrowPRException("Error reading plaintext from SSLFilter"); 612 ThrowPRException("Error reading plaintext from SSLFilter");
599 } 613 }
600 bytes_processed = 0; 614 bytes_processed = 0;
601 } 615 }
602 break; 616 break;
603 } 617 }
604 618
605 case kWriteEncrypted: { 619 case kWriteEncrypted: {
606 const uint8_t* buf1; 620 const uint8_t* buf1;
607 const uint8_t* buf2; 621 const uint8_t* buf2;
608 unsigned int len1; 622 unsigned int len1;
609 unsigned int len2; 623 unsigned int len2;
610 int bytes_free = buffer_size_ - start - length; 624 int bytes_free = size - start - length;
611 memio_Private* secret = memio_GetSecret(filter_); 625 memio_Private* secret = memio_GetSecret(filter_);
612 memio_GetWriteParams(secret, &buf1, &len1, &buf2, &len2); 626 memio_GetWriteParams(secret, &buf1, &len1, &buf2, &len2);
613 int bytes_to_send = 627 int bytes_to_send =
614 dart::Utils::Minimum(len1, static_cast<unsigned>(bytes_free)); 628 dart::Utils::Minimum(len1, static_cast<unsigned>(bytes_free));
615 if (bytes_to_send > 0) { 629 if (bytes_to_send > 0) {
616 memmove(buffer + start + length, buf1, bytes_to_send); 630 memmove(buffer + start + length, buf1, bytes_to_send);
617 bytes_processed = bytes_to_send; 631 bytes_processed = bytes_to_send;
618 } 632 }
619 bytes_to_send = dart::Utils::Minimum(len2, 633 bytes_to_send = dart::Utils::Minimum(len2,
620 static_cast<unsigned>(bytes_free - bytes_processed)); 634 static_cast<unsigned>(bytes_free - bytes_processed));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 if (PR_WOULD_BLOCK_ERROR != pr_error) { 672 if (PR_WOULD_BLOCK_ERROR != pr_error) {
659 ThrowPRException("Error reading plaintext from SSLFilter"); 673 ThrowPRException("Error reading plaintext from SSLFilter");
660 } 674 }
661 bytes_processed = 0; 675 bytes_processed = 0;
662 } 676 }
663 break; 677 break;
664 } 678 }
665 } 679 }
666 return bytes_processed; 680 return bytes_processed;
667 } 681 }
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket.h ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698