node
node copied to clipboard
net: add writeQueueSize
add writeQueueSize
for net.js.
- [x]
make -j4 test
(UNIX), orvcbuild test
(Windows) passes - [x] tests and/or benchmarks are included
- [x] documentation is changed or added
- [x] commit message follows commit guidelines
Review requested:
- [ ] @nodejs/net
CI: https://ci.nodejs.org/job/node-test-pull-request/45898/
CI: https://ci.nodejs.org/job/node-test-pull-request/45906/
CI: https://ci.nodejs.org/job/node-test-pull-request/45912/
CI: https://ci.nodejs.org/job/node-test-pull-request/45913/
CI: https://ci.nodejs.org/job/node-test-pull-request/45914/
I think it makes more sense to undeprecate socket.bufferSize
and add socket._handle.writeQueueSize
to the count instead of adding a new field.
@pinca I've read the source code. I think 'bytesWritten' is equal to the length of all written bytes, which includes the data has been sent and data is waiting to be sent. And 'writeQueueSize' indicates the length of bytes waiting to be sent in Libuv.
@theanarkh I was talking about socket.bufferSize
and I meant something like this:
diff --git a/lib/net.js b/lib/net.js
index eaa5e594e5..ce02019a75 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -637,7 +637,7 @@ ObjectDefineProperty(Socket.prototype, 'bufferSize', {
__proto__: null,
get: function() {
if (this._handle) {
- return this.writableLength;
+ return this._handle.writeQueueSize + this.writableLength;
}
}
});
instead of creating a new property.
Oh. Thanks. bufferSize = this.bytesWritten - this._bytesDispatched + this._handle.writeQueueSize
is it right ?
It seems socket.bytesWritten = socket._bytesDispatched + socket.<writableBuffer byte length> + <length of data written before connect>
so yes it should be correct, but I think it is unnecessarily complex.
socket.writableLength
should take into account socket.<writableBuffer byte length> + <length of data written before connect>
$ node
Welcome to Node.js v18.7.0.
Type ".help" for more information.
> var socket = net.createConnection({ port: 8080, lookup() {} });
undefined
> socket.write('foo')
true
> socket.bytesWritten
3
> socket.writableLength
3
>
I would just use socket._handle.writeQueueSize + socket.writableLength
.
I also think that socket.bytesWritten
could be simplified by using socket.writableLength
but that is a different issue.