diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-03-24 17:21:14 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-30 14:20:52 +0200 |
commit | b7cfd278a53d2b7769340ed800142f6662aa48d2 (patch) | |
tree | 4f25fde46efd0f51a7fd2cf73cb4d0338b991c10 /src/stream_base-inl.h | |
parent | 1dc8eb4bd34383830d48a704d79a2bc9ec55152f (diff) | |
download | android-node-v8-b7cfd278a53d2b7769340ed800142f6662aa48d2.tar.gz android-node-v8-b7cfd278a53d2b7769340ed800142f6662aa48d2.tar.bz2 android-node-v8-b7cfd278a53d2b7769340ed800142f6662aa48d2.zip |
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 <jasnell@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 8 |
1 files changed, 5 insertions, 3 deletions
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 <typename OtherBase> |