diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-18 22:58:27 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-25 02:01:11 +0100 |
commit | 84e02b178ad14fae0df2a514e8a39bfa50ffdc2d (patch) | |
tree | ddc0435b6bd0b7811e0bf47687777c56b2857fd0 /src/stream_base.h | |
parent | 6c257cdf271384555d0ced77104a1d6b0480e246 (diff) | |
download | android-node-v8-84e02b178ad14fae0df2a514e8a39bfa50ffdc2d.tar.gz android-node-v8-84e02b178ad14fae0df2a514e8a39bfa50ffdc2d.tar.bz2 android-node-v8-84e02b178ad14fae0df2a514e8a39bfa50ffdc2d.zip |
src: allocate Buffer memory using ArrayBuffer allocator
Always use the right allocator for memory that is turned into
an `ArrayBuffer` at a later point.
This enables embedders to use their own `ArrayBuffer::Allocator`s,
and is inspired by Electron’s electron/node@f61bae3440e. It should
render their downstream patch unnecessary.
Refs: https://github.com/electron/node/commit/f61bae3440e1bfcc83bba6ff0785adfb89b4045e
PR-URL: https://github.com/nodejs/node/pull/26207
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/stream_base.h')
-rw-r--r-- | src/stream_base.h | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/stream_base.h b/src/stream_base.h index d5b2235f0e..33cf62a0c8 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -74,24 +74,17 @@ class ShutdownWrap : public StreamReq { class WriteWrap : public StreamReq { public: - char* Storage(); - size_t StorageSize() const; - void SetAllocatedStorage(char* data, size_t size); + void SetAllocatedStorage(AllocatedBuffer&& storage); WriteWrap(StreamBase* stream, v8::Local<v8::Object> req_wrap_obj) : StreamReq(stream, req_wrap_obj) { } - ~WriteWrap() override { - free(storage_); - } - // Call stream()->EmitAfterWrite() and dispose of this request wrap. void OnDone(int status) override; private: - char* storage_ = nullptr; - size_t storage_size_ = 0; + AllocatedBuffer storage_; }; @@ -115,7 +108,7 @@ class StreamListener { // It is not valid to return a zero-length buffer from this method. // It is not guaranteed that the corresponding `OnStreamRead()` call // happens in the same event loop turn as this call. - virtual uv_buf_t OnStreamAlloc(size_t suggested_size); + virtual uv_buf_t OnStreamAlloc(size_t suggested_size) = 0; // `OnStreamRead()` is called when data is available on the socket and has // been read into the buffer provided by `OnStreamAlloc()`. @@ -181,6 +174,7 @@ class ReportWritesToJSStreamListener : public StreamListener { // JS land via the handle’s .ondata method. class EmitToJSStreamListener : public ReportWritesToJSStreamListener { public: + uv_buf_t OnStreamAlloc(size_t suggested_size) override; void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override; }; |