Permalink
Browse files

[tls] use chunk size larger than 1400 if we need to write buffer in m…

…ore than 64 1400b pieces
  • Loading branch information...
indutny committed Apr 12, 2011
1 parent 311b60c commit f087e02da305e8701c0402323598a356ab938c59
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/tls.js
View
@@ -387,11 +387,17 @@ CleartextStream.prototype._pendingBytes = function() {
CleartextStream.prototype._puller = function(b) {
debug('clearIn ' + b.length + ' bytes');
- var result = 0;
+ var result = 0,
+ blen = b.length,
+ delta = Math.max(1400, Math.round(blen / 64));
- for (var offset = 0, len = b.length; offset < len; offset += 1400) {
- var chunk = b.slice(offset, Math.min(len, offset + 1400));
- result += this.pair._ssl.clearIn(chunk, 0, chunk.length);
+ for (var offset = 0; offset < blen; offset += delta) {
+ var chunk = b.slice(offset, Math.min(blen, offset + delta)),
+ local_result = this.pair._ssl.clearIn(chunk, 0, chunk.length);
+
+ if (local_result < 0) return local_result;
+
+ result += local_result;
}
return result;

0 comments on commit f087e02

Please sign in to comment.