Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
src: rename StreamWrap to LibuvStreamWrap
Browse files Browse the repository at this point in the history
This should help clarify what kind of resource a `StreamWrap`
represents.

PR-URL: nodejs/node#16157
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
addaleax committed Oct 15, 2017
1 parent 322053b commit 1fb747a
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 63 deletions.
8 changes: 4 additions & 4 deletions src/connection_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ template <typename WrapType, typename UVType>
ConnectionWrap<WrapType, UVType>::ConnectionWrap(Environment* env,
Local<Object> object,
ProviderType provider)
: StreamWrap(env,
object,
reinterpret_cast<uv_stream_t*>(&handle_),
provider) {}
: LibuvStreamWrap(env,
object,
reinterpret_cast<uv_stream_t*>(&handle_),
provider) {}


template <typename WrapType, typename UVType>
Expand Down
2 changes: 1 addition & 1 deletion src/connection_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace node {

template <typename WrapType, typename UVType>
class ConnectionWrap : public StreamWrap {
class ConnectionWrap : public LibuvStreamWrap {
public:
UVType* UVHandle() {
return &handle_;
Expand Down
4 changes: 2 additions & 2 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void PipeWrap::Initialize(Local<Object> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& 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);
Expand Down
77 changes: 39 additions & 38 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ using v8::Object;
using v8::Value;


void StreamWrap::Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
void LibuvStreamWrap::Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);

auto is_construct_call_callback =
Expand Down Expand Up @@ -85,10 +85,10 @@ void StreamWrap::Initialize(Local<Object> target,
}


StreamWrap::StreamWrap(Environment* env,
Local<Object> object,
uv_stream_t* stream,
AsyncWrap::ProviderType provider)
LibuvStreamWrap::LibuvStreamWrap(Environment* env,
Local<Object> object,
uv_stream_t* stream,
AsyncWrap::ProviderType provider)
: HandleWrap(env,
object,
reinterpret_cast<uv_handle_t*>(stream),
Expand All @@ -101,15 +101,15 @@ StreamWrap::StreamWrap(Environment* env,
}


void StreamWrap::AddMethods(Environment* env,
v8::Local<v8::FunctionTemplate> target,
int flags) {
void LibuvStreamWrap::AddMethods(Environment* env,
v8::Local<v8::FunctionTemplate> target,
int flags) {
env->SetProtoMethod(target, "setBlocking", SetBlocking);
StreamBase::AddMethods<StreamWrap>(env, target, flags);
StreamBase::AddMethods<LibuvStreamWrap>(env, target, flags);
}


int StreamWrap::GetFD() {
int LibuvStreamWrap::GetFD() {
int fd = -1;
#if !defined(_WIN32)
if (stream() != nullptr)
Expand All @@ -119,53 +119,53 @@ 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<uv_handle_t*>(stream()));
}


void* StreamWrap::Cast() {
void* LibuvStreamWrap::Cast() {
return reinterpret_cast<void*>(this);
}


AsyncWrap* StreamWrap::GetAsyncWrap() {
AsyncWrap* LibuvStreamWrap::GetAsyncWrap() {
return static_cast<AsyncWrap*>(this);
}


bool StreamWrap::IsIPCPipe() {
bool LibuvStreamWrap::IsIPCPipe() {
return is_named_pipe_ipc();
}


void StreamWrap::UpdateWriteQueueSize() {
void LibuvStreamWrap::UpdateWriteQueueSize() {
HandleScope scope(env()->isolate());
Local<Integer> write_queue_size =
Integer::NewFromUnsigned(env()->isolate(), stream()->write_queue_size);
object()->Set(env()->write_queue_size_string(), write_queue_size);
}


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<StreamWrap*>(handle->data);
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(handle->data);
HandleScope scope(wrap->env()->isolate());
Context::Scope context_scope(wrap->env()->context());

Expand All @@ -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 <class WrapType, class UVType>
static Local<Object> AcceptHandle(Environment* env, StreamWrap* parent) {
static Local<Object> AcceptHandle(Environment* env, LibuvStreamWrap* parent) {
EscapableHandleScope scope(env->isolate());
Local<Object> wrap_obj;
UVType* handle;
Expand All @@ -202,11 +202,11 @@ static Local<Object> 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<StreamWrap*>(ctx);
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(ctx);
Environment* env = wrap->env();
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Expand Down Expand Up @@ -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<StreamWrap*>(handle->data);
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(handle->data);
HandleScope scope(wrap->env()->isolate());
Context::Scope context_scope(wrap->env()->context());
uv_handle_type type = UV_UNKNOWN_HANDLE;
Expand All @@ -273,8 +273,8 @@ void StreamWrap::OnRead(uv_stream_t* handle,
}


void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {
StreamWrap* wrap;
void LibuvStreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {
LibuvStreamWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());

CHECK_GT(args.Length(), 0);
Expand All @@ -286,15 +286,15 @@ void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& 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();
return err;
}


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());
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand All @@ -381,11 +381,12 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
}


void StreamWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) {
StreamWrap* wrap = static_cast<StreamWrap*>(ctx);
void LibuvStreamWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) {
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(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)
15 changes: 6 additions & 9 deletions src/stream_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Object> target,
v8::Local<v8::Value> unused,
Expand Down Expand Up @@ -78,12 +75,12 @@ class StreamWrap : public HandleWrap, public StreamBase {
}

protected:
StreamWrap(Environment* env,
v8::Local<v8::Object> object,
uv_stream_t* stream,
AsyncWrap::ProviderType provider);
LibuvStreamWrap(Environment* env,
v8::Local<v8::Object> object,
uv_stream_t* stream,
AsyncWrap::ProviderType provider);

~StreamWrap() {
~LibuvStreamWrap() {
}

AsyncWrap* GetAsyncWrap() override;
Expand Down
2 changes: 1 addition & 1 deletion src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void TCPWrap::Initialize(Local<Object> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void TLSWrap::Wrap(const FunctionCallbackInfo<Value>& 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(
Expand Down
10 changes: 5 additions & 5 deletions src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void TTYWrap::Initialize(Local<Object> 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);
Expand Down Expand Up @@ -169,10 +169,10 @@ TTYWrap::TTYWrap(Environment* env,
int fd,
bool readable,
int* init_err)
: StreamWrap(env,
object,
reinterpret_cast<uv_stream_t*>(&handle_),
AsyncWrap::PROVIDER_TTYWRAP) {
: LibuvStreamWrap(env,
object,
reinterpret_cast<uv_stream_t*>(&handle_),
AsyncWrap::PROVIDER_TTYWRAP) {
*init_err = uv_tty_init(env->event_loop(), &handle_, fd, readable);
if (*init_err != 0)
MarkAsUninitialized();
Expand Down
2 changes: 1 addition & 1 deletion src/tty_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace node {

class TTYWrap : public StreamWrap {
class TTYWrap : public LibuvStreamWrap {
public:
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
Expand Down

0 comments on commit 1fb747a

Please sign in to comment.