Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/tls.js
Expand Up @@ -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;
}
Expand All @@ -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.
Expand Down
37 changes: 34 additions & 3 deletions src/node_crypto.cc
Expand Up @@ -959,12 +959,43 @@ 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) {
// If we has failed to write first chunk
// total_bytes_written can have negative value
if (total_bytes_written == 0) {
total_bytes_written += bytes_written;
}
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));
}


Expand Down