diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-10-29 17:15:36 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-11-06 01:07:04 +0300 |
commit | 973f324463a91721cc8a1158a5ab10ad0dd69019 (patch) | |
tree | a7664cbcc50c0fe7eced11fb20e49dc255abfe1e /src/stream_base.cc | |
parent | f17e414dc4b5d80dd5b5c7ee7107659ec5ebeb1a (diff) |
child_process,cluster: allow using V8 serialization API
Add an `serialization` option that allows child process IPC to
use the (typically more powerful) V8 serialization API.
Fixes: https://github.com/nodejs/node/issues/10965
PR-URL: https://github.com/nodejs/node/pull/30162
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r-- | src/stream_base.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc index 52163e2e43f..eaccfc995c7 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -180,12 +180,26 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) { } Local<Object> req_wrap_obj = args[0].As<Object>(); - uv_buf_t buf; buf.base = Buffer::Data(args[1]); buf.len = Buffer::Length(args[1]); - StreamWriteResult res = Write(&buf, 1, nullptr, req_wrap_obj); + uv_stream_t* send_handle = nullptr; + + if (args[2]->IsObject() && IsIPCPipe()) { + Local<Object> send_handle_obj = args[2].As<Object>(); + + HandleWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, send_handle_obj, UV_EINVAL); + send_handle = reinterpret_cast<uv_stream_t*>(wrap->GetHandle()); + // Reference LibuvStreamWrap instance to prevent it from being garbage + // collected before `AfterWrite` is called. + req_wrap_obj->Set(env->context(), + env->handle_string(), + send_handle_obj).Check(); + } + + StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj); SetWriteResult(res); return res.err; |