Browse Source

TLS: Make _cycle reentrant.

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
19b4c27ebf
  1. 16
      lib/tls.js

16
lib/tls.js

@ -69,7 +69,9 @@ CryptoStream.prototype.write = function(data /* , encoding, cb */) {
this._pending.push(data); this._pending.push(data);
this._pendingCallbacks.push(cb); this._pendingCallbacks.push(cb);
this.pair._writeCalled = true;
this.pair._cycle(); this.pair._cycle();
return this._writeState; return this._writeState;
}; };
@ -507,6 +509,11 @@ SecurePair.prototype._cycle = function() {
return; return;
} }
// Make this function reentrant.
if (this._cycleLock) return;
this._cycleLock = true;
this._writeCalled = false;
var established = this._secureEstablished; var established = this._secureEstablished;
this.encrypted._pull(); this.encrypted._pull();
@ -514,8 +521,15 @@ SecurePair.prototype._cycle = function() {
this.cleartext._push(); this.cleartext._push();
this.encrypted._push(); this.encrypted._push();
if (!established && this._secureEstablished) { this._cycleLock = false;
if (this._done) {
return;
}
if ((!established && this._secureEstablished) || this._writeCalled) {
// If we were not established but now we are, let's cycle again. // If we were not established but now we are, let's cycle again.
// Or if there is some data to write...
this._cycle(); this._cycle();
} }
}; };

Loading…
Cancel
Save