diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-11-03 20:13:18 +0100 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-11-03 14:46:28 -0700 |
commit | a5f3b3a6dab18e32ee5e7d0d79a63cec0d5d5cc5 (patch) | |
tree | be72fa320672dca39459a2fb957e973a6fc06f0b | |
parent | 5d0436fbeafeb0498d82430d38650b65a5c4220d (diff) | |
download | android-node-v8-a5f3b3a6dab18e32ee5e7d0d79a63cec0d5d5cc5.tar.gz android-node-v8-a5f3b3a6dab18e32ee5e7d0d79a63cec0d5d5cc5.tar.bz2 android-node-v8-a5f3b3a6dab18e32ee5e7d0d79a63cec0d5d5cc5.zip |
src: add method to compute storage in WriteWrap
`WriteWrap` instances may contain extra storage space.
`self_size()` returns the size of the *entire* struct, member fields as
well as storage space, so it is not an accurate measure for the
storage space available.
Add a method `ExtraSize()` (like the existing `Extra()` for accessing
the storage memory) that yields the wanted value, and use it
in the HTTP2 impl to fix a crash.
PR-URL: https://github.com/nodejs/node/pull/16727
Refs: https://github.com/nodejs/node/pull/16669
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r-- | src/node_http2_core-inl.h | 4 | ||||
-rw-r--r-- | src/stream_base-inl.h | 4 | ||||
-rw-r--r-- | src/stream_base.h | 1 |
3 files changed, 7 insertions, 2 deletions
diff --git a/src/node_http2_core-inl.h b/src/node_http2_core-inl.h index eda8a93ee7..c78e5d673f 100644 --- a/src/node_http2_core-inl.h +++ b/src/node_http2_core-inl.h @@ -503,7 +503,7 @@ inline void Nghttp2Session::SendPendingData() { while ((srcLength = nghttp2_session_mem_send(session_, &src)) > 0) { if (req == nullptr) { req = AllocateSend(); - destRemaining = req->self_size(); + destRemaining = req->ExtraSize(); dest = req->Extra(); } DEBUG_HTTP2("Nghttp2Session %s: nghttp2 has %d bytes to send\n", @@ -525,7 +525,7 @@ inline void Nghttp2Session::SendPendingData() { srcRemaining -= destRemaining; srcOffset += destRemaining; req = AllocateSend(); - destRemaining = req->self_size(); + destRemaining = req->ExtraSize(); dest = req->Extra(); } diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 667c0a9ffb..e1e50802f2 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -160,6 +160,10 @@ char* WriteWrap::Extra(size_t offset) { offset; } +size_t WriteWrap::ExtraSize() const { + return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize); +} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/stream_base.h b/src/stream_base.h index 9833a82636..20cb0155c9 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -77,6 +77,7 @@ class WriteWrap: public ReqWrap<uv_write_t>, size_t extra = 0); inline void Dispose(); inline char* Extra(size_t offset = 0); + inline size_t ExtraSize() const; inline StreamBase* wrap() const { return wrap_; } |