From 00fe76d2df4651b453a906fac0cccc5fcafb067a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 12 Oct 2017 07:11:03 +0200 Subject: [PATCH] src: rename StreamWrap to LibuvStreamWrap This should help clarify what kind of resource a `StreamWrap` represents. PR-URL: https://github.com/nodejs/node/pull/16157 Reviewed-By: Daniel Bevenius Reviewed-By: Daijiro Wachi Reviewed-By: Franziska Hinkelmann Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Joyee Cheung --- src/connection_wrap.cc | 8 ++--- src/connection_wrap.h | 2 +- src/pipe_wrap.cc | 4 +-- src/stream_base.cc | 2 +- src/stream_wrap.cc | 77 +++++++++++++++++++++--------------------- src/stream_wrap.h | 15 ++++---- src/tcp_wrap.cc | 2 +- src/tls_wrap.cc | 2 +- src/tty_wrap.cc | 10 +++--- src/tty_wrap.h | 2 +- 10 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index d894ef6cc0..a7f08ecc19 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -24,10 +24,10 @@ template ConnectionWrap::ConnectionWrap(Environment* env, Local object, ProviderType provider) - : StreamWrap(env, - object, - reinterpret_cast(&handle_), - provider) {} + : LibuvStreamWrap(env, + object, + reinterpret_cast(&handle_), + provider) {} template diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 99fe5697ed..096672efdd 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -10,7 +10,7 @@ namespace node { template -class ConnectionWrap : public StreamWrap { +class ConnectionWrap : public LibuvStreamWrap { public: UVType* UVHandle() { return &handle_; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index bf1ddbdc0d..72dd99c1e5 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -80,9 +80,9 @@ void PipeWrap::Initialize(Local target, env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); #ifdef _WIN32 - StreamWrap::AddMethods(env, t); + LibuvStreamWrap::AddMethods(env, t); #else - StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); + LibuvStreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); #endif env->SetProtoMethod(t, "bind", Bind); diff --git a/src/stream_base.cc b/src/stream_base.cc index d753dea318..a923fc669f 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -365,7 +365,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo& args) { HandleWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, send_handle_obj, UV_EINVAL); send_handle = wrap->GetHandle(); - // Reference StreamWrap instance to prevent it from being garbage + // Reference LibuvStreamWrap instance to prevent it from being garbage // collected before `AfterWrite` is called. CHECK_EQ(false, req_wrap->persistent().IsEmpty()); req_wrap_obj->Set(env->handle_string(), send_handle_obj); diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 1e3863cad2..660702eb35 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -54,9 +54,9 @@ using v8::Object; using v8::Value; -void StreamWrap::Initialize(Local target, - Local unused, - Local context) { +void LibuvStreamWrap::Initialize(Local target, + Local unused, + Local context) { Environment* env = Environment::GetCurrent(context); auto is_construct_call_callback = @@ -85,10 +85,10 @@ void StreamWrap::Initialize(Local target, } -StreamWrap::StreamWrap(Environment* env, - Local object, - uv_stream_t* stream, - AsyncWrap::ProviderType provider) +LibuvStreamWrap::LibuvStreamWrap(Environment* env, + Local object, + uv_stream_t* stream, + AsyncWrap::ProviderType provider) : HandleWrap(env, object, reinterpret_cast(stream), @@ -101,15 +101,15 @@ StreamWrap::StreamWrap(Environment* env, } -void StreamWrap::AddMethods(Environment* env, - v8::Local target, - int flags) { +void LibuvStreamWrap::AddMethods(Environment* env, + v8::Local target, + int flags) { env->SetProtoMethod(target, "setBlocking", SetBlocking); - StreamBase::AddMethods(env, target, flags); + StreamBase::AddMethods(env, target, flags); } -int StreamWrap::GetFD() { +int LibuvStreamWrap::GetFD() { int fd = -1; #if !defined(_WIN32) if (stream() != nullptr) @@ -119,32 +119,32 @@ int StreamWrap::GetFD() { } -bool StreamWrap::IsAlive() { +bool LibuvStreamWrap::IsAlive() { return HandleWrap::IsAlive(this); } -bool StreamWrap::IsClosing() { +bool LibuvStreamWrap::IsClosing() { return uv_is_closing(reinterpret_cast(stream())); } -void* StreamWrap::Cast() { +void* LibuvStreamWrap::Cast() { return reinterpret_cast(this); } -AsyncWrap* StreamWrap::GetAsyncWrap() { +AsyncWrap* LibuvStreamWrap::GetAsyncWrap() { return static_cast(this); } -bool StreamWrap::IsIPCPipe() { +bool LibuvStreamWrap::IsIPCPipe() { return is_named_pipe_ipc(); } -void StreamWrap::UpdateWriteQueueSize() { +void LibuvStreamWrap::UpdateWriteQueueSize() { HandleScope scope(env()->isolate()); Local write_queue_size = Integer::NewFromUnsigned(env()->isolate(), stream()->write_queue_size); @@ -152,20 +152,20 @@ void StreamWrap::UpdateWriteQueueSize() { } -int StreamWrap::ReadStart() { +int LibuvStreamWrap::ReadStart() { return uv_read_start(stream(), OnAlloc, OnRead); } -int StreamWrap::ReadStop() { +int LibuvStreamWrap::ReadStop() { return uv_read_stop(stream()); } -void StreamWrap::OnAlloc(uv_handle_t* handle, +void LibuvStreamWrap::OnAlloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - StreamWrap* wrap = static_cast(handle->data); + LibuvStreamWrap* wrap = static_cast(handle->data); HandleScope scope(wrap->env()->isolate()); Context::Scope context_scope(wrap->env()->context()); @@ -175,14 +175,14 @@ void StreamWrap::OnAlloc(uv_handle_t* handle, } -void StreamWrap::OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx) { +void LibuvStreamWrap::OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx) { buf->base = node::Malloc(size); buf->len = size; } template -static Local AcceptHandle(Environment* env, StreamWrap* parent) { +static Local AcceptHandle(Environment* env, LibuvStreamWrap* parent) { EscapableHandleScope scope(env->isolate()); Local wrap_obj; UVType* handle; @@ -202,11 +202,11 @@ static Local AcceptHandle(Environment* env, StreamWrap* parent) { } -void StreamWrap::OnReadImpl(ssize_t nread, +void LibuvStreamWrap::OnReadImpl(ssize_t nread, const uv_buf_t* buf, uv_handle_type pending, void* ctx) { - StreamWrap* wrap = static_cast(ctx); + LibuvStreamWrap* wrap = static_cast(ctx); Environment* env = wrap->env(); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); @@ -244,10 +244,10 @@ void StreamWrap::OnReadImpl(ssize_t nread, } -void StreamWrap::OnRead(uv_stream_t* handle, +void LibuvStreamWrap::OnRead(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { - StreamWrap* wrap = static_cast(handle->data); + LibuvStreamWrap* wrap = static_cast(handle->data); HandleScope scope(wrap->env()->isolate()); Context::Scope context_scope(wrap->env()->context()); uv_handle_type type = UV_UNKNOWN_HANDLE; @@ -273,8 +273,8 @@ void StreamWrap::OnRead(uv_stream_t* handle, } -void StreamWrap::SetBlocking(const FunctionCallbackInfo& args) { - StreamWrap* wrap; +void LibuvStreamWrap::SetBlocking(const FunctionCallbackInfo& args) { + LibuvStreamWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); CHECK_GT(args.Length(), 0); @@ -286,7 +286,7 @@ void StreamWrap::SetBlocking(const FunctionCallbackInfo& args) { } -int StreamWrap::DoShutdown(ShutdownWrap* req_wrap) { +int LibuvStreamWrap::DoShutdown(ShutdownWrap* req_wrap) { int err; err = uv_shutdown(req_wrap->req(), stream(), AfterShutdown); req_wrap->Dispatched(); @@ -294,7 +294,7 @@ int StreamWrap::DoShutdown(ShutdownWrap* req_wrap) { } -void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { +void LibuvStreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { ShutdownWrap* req_wrap = ShutdownWrap::from_req(req); CHECK_NE(req_wrap, nullptr); HandleScope scope(req_wrap->env()->isolate()); @@ -307,7 +307,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { // values, shifting their base and decrementing their length. This is // required in order to skip the data that was successfully written via // uv_try_write(). -int StreamWrap::DoTryWrite(uv_buf_t** bufs, size_t* count) { +int LibuvStreamWrap::DoTryWrite(uv_buf_t** bufs, size_t* count) { int err; size_t written; uv_buf_t* vbufs = *bufs; @@ -343,7 +343,7 @@ int StreamWrap::DoTryWrite(uv_buf_t** bufs, size_t* count) { } -int StreamWrap::DoWrite(WriteWrap* w, +int LibuvStreamWrap::DoWrite(WriteWrap* w, uv_buf_t* bufs, size_t count, uv_stream_t* send_handle) { @@ -372,7 +372,7 @@ int StreamWrap::DoWrite(WriteWrap* w, } -void StreamWrap::AfterWrite(uv_write_t* req, int status) { +void LibuvStreamWrap::AfterWrite(uv_write_t* req, int status) { WriteWrap* req_wrap = WriteWrap::from_req(req); CHECK_NE(req_wrap, nullptr); HandleScope scope(req_wrap->env()->isolate()); @@ -381,11 +381,12 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) { } -void StreamWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) { - StreamWrap* wrap = static_cast(ctx); +void LibuvStreamWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) { + LibuvStreamWrap* wrap = static_cast(ctx); wrap->UpdateWriteQueueSize(); } } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(stream_wrap, node::StreamWrap::Initialize) +NODE_MODULE_CONTEXT_AWARE_BUILTIN(stream_wrap, + node::LibuvStreamWrap::Initialize) diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 584e524df5..d8fbcf709a 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -33,10 +33,7 @@ namespace node { -// Forward declaration -class StreamWrap; - -class StreamWrap : public HandleWrap, public StreamBase { +class LibuvStreamWrap : public HandleWrap, public StreamBase { public: static void Initialize(v8::Local target, v8::Local unused, @@ -78,12 +75,12 @@ class StreamWrap : public HandleWrap, public StreamBase { } protected: - StreamWrap(Environment* env, - v8::Local object, - uv_stream_t* stream, - AsyncWrap::ProviderType provider); + LibuvStreamWrap(Environment* env, + v8::Local object, + uv_stream_t* stream, + AsyncWrap::ProviderType provider); - ~StreamWrap() { + ~LibuvStreamWrap() { } AsyncWrap* GetAsyncWrap() override; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 2bbc350dd5..fdb8244bf6 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -90,7 +90,7 @@ void TCPWrap::Initialize(Local target, env->SetProtoMethod(t, "unref", HandleWrap::Unref); env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); + LibuvStreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); env->SetProtoMethod(t, "open", Open); env->SetProtoMethod(t, "bind", Bind); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 093dc72af3..738bd04071 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -183,7 +183,7 @@ void TLSWrap::Wrap(const FunctionCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsObject()) { return env->ThrowTypeError( - "First argument should be a StreamWrap instance"); + "First argument should be a LibuvStreamWrap instance"); } if (args.Length() < 2 || !args[1]->IsObject()) { return env->ThrowTypeError( diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index ee793056c8..ca84008785 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -63,7 +63,7 @@ void TTYWrap::Initialize(Local target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown); + LibuvStreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown); env->SetProtoMethod(t, "getWindowSize", TTYWrap::GetWindowSize); env->SetProtoMethod(t, "setRawMode", SetRawMode); @@ -169,10 +169,10 @@ TTYWrap::TTYWrap(Environment* env, int fd, bool readable, int* init_err) - : StreamWrap(env, - object, - reinterpret_cast(&handle_), - AsyncWrap::PROVIDER_TTYWRAP) { + : LibuvStreamWrap(env, + object, + reinterpret_cast(&handle_), + AsyncWrap::PROVIDER_TTYWRAP) { *init_err = uv_tty_init(env->event_loop(), &handle_, fd, readable); } diff --git a/src/tty_wrap.h b/src/tty_wrap.h index 7b7cb5ece8..75c3e6a217 100644 --- a/src/tty_wrap.h +++ b/src/tty_wrap.h @@ -30,7 +30,7 @@ namespace node { -class TTYWrap : public StreamWrap { +class TTYWrap : public LibuvStreamWrap { public: static void Initialize(v8::Local target, v8::Local unused,