summaryrefslogtreecommitdiff
path: root/src/stream_base.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r--src/stream_base.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc
index 52163e2e43..eaccfc995c 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;