From b7cfd278a53d2b7769340ed800142f6662aa48d2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 24 Mar 2018 17:21:14 +0100 Subject: src: clean up `req.bytes` tracking Simply always tell the caller how many bytes were written, rather than letting them track it. In the case of writing a string, also keep track of the bytes written by the earlier `DoTryWrite()`. Refs: https://github.com/nodejs/node/issues/19562 PR-URL: https://github.com/nodejs/node/pull/19551 Reviewed-By: James M Snell --- src/stream_base-inl.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/stream_base-inl.h') diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 35e49dfea2..392dc2c87c 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -194,13 +194,15 @@ inline StreamWriteResult StreamBase::Write( Environment* env = stream_env(); int err; + size_t total_bytes = 0; for (size_t i = 0; i < count; ++i) - bytes_written_ += bufs[i].len; + total_bytes += bufs[i].len; + bytes_written_ += total_bytes; if (send_handle == nullptr) { err = DoTryWrite(&bufs, &count); if (err != 0 || count == 0) { - return StreamWriteResult { false, err, nullptr }; + return StreamWriteResult { false, err, nullptr, total_bytes }; } } @@ -230,7 +232,7 @@ inline StreamWriteResult StreamBase::Write( ClearError(); } - return StreamWriteResult { async, err, req_wrap }; + return StreamWriteResult { async, err, req_wrap, total_bytes }; } template -- cgit v1.2.3