Skip to content
Browse files

[tls] write buffer by chunks according to that recommendation: http:/…

  • Loading branch information...
1 parent 425b57b commit 89cae9a00988883a755c9f77d6a718c19573b610 @indutny committed
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/tls.js
View
17 lib/tls.js
@@ -386,7 +386,22 @@ CleartextStream.prototype._pendingBytes = function() {
CleartextStream.prototype._puller = function(b) {
debug('clearIn ' + b.length + ' bytes');
- return this.pair._ssl.clearIn(b, 0, b.length);
+
+ var total = b.length,
+ chunkSize = 1400;
+
+ var result = 0;
+ for (var i = 0; i < total; i += chunkSize) {
+ var chunkEnd = Math.min(total, i + chunkSize),
+ chunkLen = chunkEnd - i,
+ chunk = b.slice(i, chunkEnd),
+ clearResult = this.pair._ssl.clearIn(chunk, 0, chunkLen);
+
+ if (clearResult < 0) return clearResult;
+ if (clearResult < chunkLen) return result + clearResult;
+ result += clearResult;
+ }
+ return result;
};

0 comments on commit 89cae9a

Please sign in to comment.
Something went wrong with that request. Please try again.