Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: fix bufferSize #34088

Closed
wants to merge 2 commits into from
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
15 changes: 15 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,19 @@ const moduleParents = Object.values(require.cache)
.filter((m) => m.children.includes(module));
```

<a id="DEP0XXX"></a>
### DEP0XXX: `socket.bufferSize`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
description: Documentation-only deprecation.
-->

Type: Documentation-only

[`socket.bufferSize`][] is just an alias for [`writable.writableLength`][].

[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
Expand Down Expand Up @@ -2824,6 +2837,7 @@ const moduleParents = Object.values(require.cache)
[`script.createCachedData()`]: vm.html#vm_script_createcacheddata
[`setInterval()`]: timers.html#timers_setinterval_callback_delay_args
[`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args
[`socket.bufferSize`]: net.html#net_socket_buffersize
[`timeout.ref()`]: timers.html#timers_timeout_ref
[`timeout.refresh()`]: timers.html#timers_timeout_refresh
[`timeout.unref()`]: timers.html#timers_timeout_unref
Expand Down Expand Up @@ -2860,6 +2874,7 @@ const moduleParents = Object.values(require.cache)
[`util`]: util.html
[`worker.exitedAfterDisconnect`]: cluster.html#cluster_worker_exitedafterdisconnect
[`worker.terminate()`]: worker_threads.html#worker_threads_worker_terminate
[`writable.writableLength`]: stream.html#stream_writable_writablelength
[`zlib.bytesWritten`]: zlib.html#zlib_zlib_byteswritten
[Legacy URL API]: url.html#url_legacy_url_api
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
Expand Down
5 changes: 5 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,12 @@ socket as reported by the operating system:
### `socket.bufferSize`
<!-- YAML
added: v0.3.8
deprecated:
- REPLACEME
-->

> Stability: 0 - Deprecated: Use [`writable.writableLength`][] instead.

* {integer}

This property shows the number of characters buffered for writing. The buffer
Expand Down Expand Up @@ -1268,6 +1272,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
[`socket.setEncoding()`]: #net_socket_setencoding_encoding
[`socket.setTimeout()`]: #net_socket_settimeout_timeout_callback
[`socket.setTimeout(timeout)`]: #net_socket_settimeout_timeout_callback
[`writable.writableLength`]: stream.html#stream_writable_writablelength
[`writable.destroyed`]: stream.html#stream_writable_destroyed
[`writable.destroy()`]: stream.html#stream_writable_destroy_error
[`writable.end()`]: stream.html#stream_writable_end_chunk_encoding_callback
Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ ObjectDefineProperty(Socket.prototype, 'readyState', {
ObjectDefineProperty(Socket.prototype, 'bufferSize', {
get: function() {
if (this._handle) {
return this[kLastWriteQueueSize] + this.writableLength;
return this.writableLength;
Copy link
Member

Choose a reason for hiding this comment

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

I don’t think we need to guard this on if (this._handle) anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are some tests that expect undefined when there is no handle.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changing that would probably make this semver-major?

Copy link
Member

Choose a reason for hiding this comment

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

Hm yeah, I guess.

}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-buffersize.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ server.listen(0, common.mustCall(() => {

for (let i = 1; i < iter; i++) {
client.write('a');
assert.strictEqual(client.bufferSize, i + 1);
assert.strictEqual(client.bufferSize, i);
}

client.on('finish', common.mustCall(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-streamwrap-buffersize.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const net = require('net');

for (let i = 1; i < iter; i++) {
client.write('a');
assert.strictEqual(client.bufferSize, i + 1);
assert.strictEqual(client.bufferSize, i);
}

client.on('end', common.mustCall());
Expand Down