Permalink
Browse files

[tls] write data by small (1500 bytes) chunks, see http://www.belshe.…

  • Loading branch information...
1 parent c9b40da commit d6cc47f40e7662eb16172b893c62e19f70430196 @indutny committed Apr 21, 2011
Showing with 31 additions and 7 deletions.
  1. +2 −4 lib/tls.js
  2. +29 −3 src/node_crypto.cc
View
@@ -382,8 +382,8 @@ CryptoStream.prototype._pull = function() {
this.pair._maybeInitFinished();
- if (rv === 0 || rv < 0) {
- this._pending.unshift(tmp);
+ if (rv < tmp.length) {
+ this._pending.unshift(tmp.slice(Math.max(rv, 0)));
this._pendingCallbacks.unshift(cb);
break;
}
@@ -392,8 +392,6 @@ CryptoStream.prototype._pull = function() {
assert(this._pendingBytes >= 0);
if (cb) cb();
-
- assert(rv === tmp.length);
}
// If we've cleared all of incoming encrypted data, emit drain.
View
@@ -959,12 +959,38 @@ Handle<Value> Connection::ClearIn(const Arguments& args) {
if (rv < 0) return scope.Close(Integer::New(rv));
}
- int bytes_written = SSL_write(ss->ssl_, buffer_data + off, len);
+ const int chunkSize = 1500;
+ int rv = 0;
+ int offset = 0;
+ int total_bytes_written = 0;
+
+ while (len > 0) {
+ int chunkSize_ = chunkSize > len ? len : chunkSize;
+ int bytes_written = SSL_write(ss->ssl_,
+ buffer_data + off + offset,
+ chunkSize_);
+ bytes_written = ss->HandleSSLError("SSL_write:ClearIn",
+ bytes_written);
+
+ // Written nothing at all
+ if (bytes_written <= 0) {
+ break;
+ }
+
+ total_bytes_written += bytes_written;
+
+ // Written less than planned
+ if (bytes_written < chunkSize_) {
+ break;
+ }
+
+ offset += chunkSize_;
+ len -= chunkSize_;
+ }
- ss->HandleSSLError("SSL_write:ClearIn", bytes_written);
ss->SetShutdownFlags();
- return scope.Close(Integer::New(bytes_written));
+ return scope.Close(Integer::New(total_bytes_written));
}

0 comments on commit d6cc47f

Please sign in to comment.