mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
net: replace usage of internal stream state with public api
Refs: https://github.com/nodejs/node/issues/445 PR-URL: https://github.com/nodejs/node/pull/34885 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
This commit is contained in:
parent
7fca0df180
commit
a36b7d8960
15
lib/net.js
15
lib/net.js
@ -789,19 +789,18 @@ protoGetter('_bytesDispatched', function _bytesDispatched() {
|
||||
|
||||
protoGetter('bytesWritten', function bytesWritten() {
|
||||
let bytes = this._bytesDispatched;
|
||||
const state = this._writableState;
|
||||
const data = this._pendingData;
|
||||
const encoding = this._pendingEncoding;
|
||||
const writableBuffer = this.writableBuffer;
|
||||
|
||||
if (!state)
|
||||
if (!writableBuffer)
|
||||
return undefined;
|
||||
|
||||
this.writableBuffer.forEach(function(el) {
|
||||
if (el.chunk instanceof Buffer)
|
||||
bytes += el.chunk.length;
|
||||
else
|
||||
bytes += Buffer.byteLength(el.chunk, el.encoding);
|
||||
});
|
||||
for (const el of writableBuffer) {
|
||||
bytes += el.chunk instanceof Buffer ?
|
||||
el.chunk.length :
|
||||
Buffer.byteLength(el.chunk, el.encoding);
|
||||
}
|
||||
|
||||
if (ArrayIsArray(data)) {
|
||||
// Was a writev, iterate over chunks to get total length
|
||||
|
Loading…
Reference in New Issue
Block a user