Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
net,tls,test: remove writeQueueSize and fix bufferSize
When use TLSSocket, bufferSize is always +1, this affects users who
rely on this property to make judgments. This commit removed legacy
code and corrected the calculation of bufferSize.

Fixes: #15005
  • Loading branch information
micooz committed Aug 24, 2017
commit 035bf88c21a4f8a00fb6ba7e5b4b0b44fa6abcbd
6 changes: 0 additions & 6 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,6 @@ TLSSocket.prototype._init = function(socket, wrap) {
var options = this._tlsOptions;
var ssl = this._handle;

// lib/net.js expect this value to be non-zero if write hasn't been flushed
// immediately
// TODO(indutny): revise this solution, it might be 1 before handshake and
// represent real writeQueueSize during regular writes.
ssl.writeQueueSize = 1;

this.server = options.server;

// For clients, we will always have either a given ca list or be using
Expand Down
4 changes: 2 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ Object.defineProperty(Socket.prototype, 'readyState', {
Object.defineProperty(Socket.prototype, 'bufferSize', {
get: function() {
if (this._handle) {
return this._handle.writeQueueSize + this._writableState.length;
return this._writableState.length;
}
}
});
Expand Down Expand Up @@ -767,7 +767,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {

// If it was entirely flushed, we can write some more right now.
// However, if more is left in the queue, then wait until that clears.
if (req.async && this._handle.writeQueueSize !== 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should be left as it is.

if (req.async)
req.cb = cb;
else
cb();
Expand Down
36 changes: 36 additions & 0 deletions test/parallel/test-tls-buffersize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
require('../common');
const assert = require('assert');
const tls = require('tls');
const fixtures = require('../common/fixtures');

const options = {
key: fixtures.readSync('test_key.pem'),
cert: fixtures.readSync('test_cert.pem')
};

const iter = 10;

const server = tls.createServer(options, (socket) => {
socket.pipe(socket);
socket.on('end', () => {
server.close();
});
});

server.listen(0, () => {
const client = tls.connect({
port: server.address().port,
rejectUnauthorized: false
}, () => {
for (let i = 1; i < iter; i++) {
client.write('a');
assert.strictEqual(client.bufferSize, i);
}
client.end();
});

client.on('finish', () => {
assert.strictEqual(client.bufferSize, 0);
});
});