Browse Source

TLS: fix throttling

Re-enable test-https-large-response.js

Closes GH-614.
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
97f7c06451
  1. 36
      lib/tls.js
  2. 0
      test/pummel/test-https-large-response.js
  3. 13
      test/simple/test-tls-throttle.js

36
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');
if (this === this.pair.encrypted) {
debug('end encrypted');
this.pair.cleartext._destroyAfterPush = true;
} else {
// CleartextStream
assert(this === this.pair.cleartext);
debug('end cleartext');
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;
}

0
test/disabled/test-https-large-response.js → test/pummel/test-https-large-response.js

13
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);
});

Loading…
Cancel
Save