mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

Currently, writeQueueSize is never used in C++ and barely used within JS. Instead of constantly updating the value on the JS object, create a getter that will retrieve the most up-to-date value from C++. For the vast majority of cases though, create a new prop on Socket.prototype[kLastWriteQueueSize] using a Symbol. Use this to track the current write size, entirely in JS land. PR-URL: https://github.com/nodejs/node/pull/17650 Reviewed-By: Anna Henningsen <anna@addaleax.net>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const fixtures = require('../common/fixtures');
|
|
const tls = require('tls');
|
|
|
|
const iter = 10;
|
|
|
|
const server = tls.createServer({
|
|
key: fixtures.readKey('agent2-key.pem'),
|
|
cert: fixtures.readKey('agent2-cert.pem')
|
|
}, common.mustCall((socket) => {
|
|
let str = '';
|
|
socket.setEncoding('utf-8');
|
|
socket.on('data', (chunk) => { str += chunk; });
|
|
|
|
socket.on('end', common.mustCall(() => {
|
|
assert.strictEqual(str, 'a'.repeat(iter - 1));
|
|
server.close();
|
|
}));
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = tls.connect({
|
|
port: server.address().port,
|
|
rejectUnauthorized: false
|
|
}, common.mustCall(() => {
|
|
assert.strictEqual(client.bufferSize, 0);
|
|
|
|
for (let i = 1; i < iter; i++) {
|
|
client.write('a');
|
|
assert.strictEqual(client.bufferSize, i + 1);
|
|
}
|
|
|
|
client.on('finish', common.mustCall(() => {
|
|
assert.strictEqual(client.bufferSize, 0);
|
|
}));
|
|
|
|
client.end();
|
|
}));
|
|
}));
|