summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tls.js42
-rw-r--r--test/pummel/test-https-large-response.js (renamed from test/disabled/test-https-large-response.js)0
-rw-r--r--test/simple/test-tls-throttle.js13
3 files changed, 44 insertions, 11 deletions
diff --git a/lib/tls.js b/lib/tls.js
index b7db6efc48..6204a9cb5f 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -152,6 +152,9 @@ CryptoStream.prototype.end = function(d) {
this._pending.push(END_OF_FILE);
this._pendingCallbacks.push(null);
+ // If this is an encrypted stream then we need to disable further 'data'
+ // events.
+
this.writable = false;
this.pair._cycle();
@@ -169,6 +172,18 @@ CryptoStream.prototype.destroy = function(err) {
};
+CryptoStream.prototype._done = function() {
+ this._doneFlag = true;
+
+ if (this.pair.cleartext._doneFlag &&
+ this.pair.encrypted._doneFlag &&
+ !this.pair._done) {
+ // If both streams are done:
+ this.pair._destroy();
+ }
+};
+
+
CryptoStream.prototype.fd = -1;
CryptoStream.prototype.__defineGetter__('readyState',
net.Socket.prototype.__lookupGetter__('readyState'));
@@ -186,6 +201,11 @@ CryptoStream.prototype.__defineGetter__('readyState',
// });
//
CryptoStream.prototype._push = function() {
+ if (this == this.pair.encrypted && !this.writable) {
+ // If the encrypted side got EOF, we do not attempt
+ // to write out data anymore.
+ return;
+ }
while (this._writeState == true) {
var bytesRead = 0;
@@ -211,7 +231,7 @@ CryptoStream.prototype._push = function() {
// Bail out if we didn't read any data.
if (bytesRead == 0) {
if (this._pendingBytes() == 0 && this._destroyAfterPush) {
- this.destroy();
+ this._done();
}
return;
}
@@ -256,17 +276,23 @@ CryptoStream.prototype._pull = function() {
if (tmp === END_OF_FILE) {
// Sending EOF
- debug('end');
- this.pair._ssl.shutdown();
+ if (this === this.pair.encrypted) {
+ debug('end encrypted');
+ this.pair.cleartext._destroyAfterPush = true;
+ } else {
+ // CleartextStream
+ assert(this === this.pair.cleartext);
+ debug('end cleartext');
- // TODO check if we get EAGAIN From shutdown, would have to do it
- // again. should unshift END_OF_FILE back onto pending and wait for
- // next cycle.
+ this.pair._ssl.shutdown();
+ // TODO check if we get EAGAIN From shutdown, would have to do it
+ // again. should unshift END_OF_FILE back onto pending and wait for
+ // next cycle.
+ }
this.pair.encrypted._destroyAfterPush = true;
-
this.pair._cycle();
- //this.pair._destroy();
+ this._done()
return;
}
diff --git a/test/disabled/test-https-large-response.js b/test/pummel/test-https-large-response.js
index 625606dc62..625606dc62 100644
--- a/test/disabled/test-https-large-response.js
+++ b/test/pummel/test-https-large-response.js
diff --git a/test/simple/test-tls-throttle.js b/test/simple/test-tls-throttle.js
index 8d009ec966..ff0e5c35aa 100644
--- a/test/simple/test-tls-throttle.js
+++ b/test/simple/test-tls-throttle.js
@@ -34,6 +34,7 @@ server.listen(common.PORT, function() {
var client = tls.connect(common.PORT);
client.on('data', function(d) {
+ process.stdout.write('.');
recvCount += d.length;
client.pause();
@@ -44,18 +45,24 @@ server.listen(common.PORT, function() {
client.on('close', function() {
+ console.error('close');
server.close();
clearTimeout(timeout);
});
});
-var timeout = setTimeout(function() {
- process.exit(1);
-}, 10*1000);
+function displayCounts() {
+ console.log('body.length: %d', body.length);
+ console.log(' recvCount: %d', recvCount);
+}
+
+
+var timeout = setTimeout(displayCounts, 10*1000);
process.on('exit', function() {
+ displayCounts();
assert.equal(1, connections);
assert.equal(body.length, recvCount);
});