diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-12-09 05:29:11 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-12-13 06:45:57 +0100 |
commit | 453008d73ef7248c809d4d1b52c127915b08fc46 (patch) | |
tree | ecccf51cbe93e3efbe48a42fde6ccb0fa495d9bf /src/stream_base-inl.h | |
parent | 24b0f67c2b0b97a4b79f9582e805785cb317daa0 (diff) | |
download | android-node-v8-453008d73ef7248c809d4d1b52c127915b08fc46.tar.gz android-node-v8-453008d73ef7248c809d4d1b52c127915b08fc46.tar.bz2 android-node-v8-453008d73ef7248c809d4d1b52c127915b08fc46.zip |
src: minor refactoring to StreamBase writes
Instead of having per-request callbacks, always call a callback
on the `StreamBase` instance itself for `WriteWrap` and `ShutdownWrap`.
This makes `WriteWrap` cleanup consistent for all stream classes,
since the after-write callback is always the same now.
If special handling is needed for writes that happen to a sub-class,
`AfterWrite` can be overridden by that class, rather than that
class providing its own callback (e.g. updating the write
queue size for libuv streams).
If special handling is needed for writes that happen on another
stream instance, the existing `after_write_cb()` callback
is used for that (e.g. custom code after writing to the
transport from a TLS stream).
As a nice bonus, this also makes `WriteWrap` and `ShutdownWrap`
instances slightly smaller.
PR-URL: https://github.com/nodejs/node/pull/17564
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 807e138ef7..29739011c6 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -143,15 +143,19 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) { } +inline void ShutdownWrap::OnDone(int status) { + stream()->AfterShutdown(this, status); +} + + WriteWrap* WriteWrap::New(Environment* env, Local<Object> obj, StreamBase* wrap, - DoneCb cb, size_t extra) { size_t storage_size = ROUND_UP(sizeof(WriteWrap), kAlignSize) + extra; char* storage = new char[storage_size]; - return new(storage) WriteWrap(env, obj, wrap, cb, storage_size); + return new(storage) WriteWrap(env, obj, wrap, storage_size); } @@ -171,6 +175,10 @@ size_t WriteWrap::ExtraSize() const { return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize); } +inline void WriteWrap::OnDone(int status) { + stream()->AfterWrite(this, status); +} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |