diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-02-16 21:09:43 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-02-16 18:10:53 -0800 |
commit | 19b4c27ebf6d0b1aa2ded64d57fa44ec70e8756e (patch) | |
tree | 7a447fb99ee678e38bbaf17ca6fb48f1abded648 | |
parent | 89bfa419a50cad962db4a44ceeea66b9809834b1 (diff) | |
download | nodejs-19b4c27ebf6d0b1aa2ded64d57fa44ec70e8756e.tar.gz nodejs-19b4c27ebf6d0b1aa2ded64d57fa44ec70e8756e.tar.bz2 nodejs-19b4c27ebf6d0b1aa2ded64d57fa44ec70e8756e.zip |
TLS: Make _cycle reentrant.
-rw-r--r-- | lib/tls.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/tls.js b/lib/tls.js index cbe706b8a..9760490b6 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -69,7 +69,9 @@ CryptoStream.prototype.write = function(data /* , encoding, cb */) { this._pending.push(data); this._pendingCallbacks.push(cb); + this.pair._writeCalled = true; this.pair._cycle(); + return this._writeState; }; @@ -507,6 +509,11 @@ SecurePair.prototype._cycle = function() { return; } + // Make this function reentrant. + if (this._cycleLock) return; + this._cycleLock = true; + this._writeCalled = false; + var established = this._secureEstablished; this.encrypted._pull(); @@ -514,8 +521,15 @@ SecurePair.prototype._cycle = function() { this.cleartext._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. + // Or if there is some data to write... this._cycle(); } }; |