From ad6dee3a74a6a9d1add71396c168e41a2efdac90 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 4 Jul 2016 19:20:33 +0200 Subject: [PATCH 01/23] src: extracting OnConnection from pipe_wrap and tcp_wrap One of the issues in #4641 concerns OnConnection in pipe_wrap and tcp_wrap which are very similar with some minor difference in how they are coded. This commit extracts OnConnection so both these classes can share the same implementation. --- node.gyp | 2 ++ src/connection_wrap.cc | 64 ++++++++++++++++++++++++++++++++++++++++++ src/connection_wrap.h | 22 +++++++++++++++ src/pipe_wrap.cc | 42 ++------------------------- src/pipe_wrap.h | 5 ++-- src/tcp_wrap.cc | 41 ++------------------------- src/tcp_wrap.h | 5 ++-- 7 files changed, 98 insertions(+), 83 deletions(-) create mode 100644 src/connection_wrap.cc create mode 100644 src/connection_wrap.h diff --git a/node.gyp b/node.gyp index a1a5284292a7aa..7ef55cfdaaf1f7 100644 --- a/node.gyp +++ b/node.gyp @@ -141,6 +141,7 @@ 'src/env.cc', 'src/fs_event_wrap.cc', 'src/cares_wrap.cc', + 'src/connection_wrap.cc', 'src/handle_wrap.cc', 'src/js_stream.cc', 'src/node.cc', @@ -177,6 +178,7 @@ 'src/async-wrap-inl.h', 'src/base-object.h', 'src/base-object-inl.h', + 'src/connection_wrap.h', 'src/debug-agent.h', 'src/env.h', 'src/env-inl.h', diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc new file mode 100644 index 00000000000000..88854fa5d51fcf --- /dev/null +++ b/src/connection_wrap.cc @@ -0,0 +1,64 @@ +#include "connection_wrap.h" + +#include "env-inl.h" +#include "env.h" +#include "pipe_wrap.h" +#include "tcp_wrap.h" +#include "util.h" +#include "util-inl.h" + +namespace node { + +using v8::Context; +using v8::HandleScope; +using v8::Integer; +using v8::Local; +using v8::Object; +using v8::Value; + + +template +void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { + WrapType* wrap_data = static_cast(handle->data); + CHECK_EQ(&wrap_data->handle_, reinterpret_cast(handle)); + + Environment* env = wrap_data->env(); + HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); + + // We should not be getting this callback if someone as already called + // uv_close() on the handle. + CHECK_EQ(wrap_data->persistent().IsEmpty(), false); + + Local argv[] = { + Integer::New(env->isolate(), status), + Undefined(env->isolate()) + }; + + if (status == 0) { + // Instanciate the client javascript object and handle. + Local client_obj = WrapType::Instantiate(env, wrap_data); + + // Unwrap the client javascript object. + WrapType* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); + uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); + if (uv_accept(handle, client_handle)) + return; + + // Successful accept. Call the onconnection callback in JavaScript land. + argv[1] = client_obj; + } + wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv); +} + +template void ConnectionWrap::OnConnection( + uv_stream_t* handle, + int status); + +template void ConnectionWrap::OnConnection( + uv_stream_t* handle, + int status); + + +} // namespace node diff --git a/src/connection_wrap.h b/src/connection_wrap.h new file mode 100644 index 00000000000000..06b2dfcfcf8437 --- /dev/null +++ b/src/connection_wrap.h @@ -0,0 +1,22 @@ +#ifndef SRC_CONNECTION_WRAP_H_ +#define SRC_CONNECTION_WRAP_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#include "env.h" +#include "v8.h" + +namespace node { + +class ConnectionWrap { + protected: + template + static void OnConnection(uv_stream_t* handle, int status); +}; + + +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#endif // SRC_CONNECTION_WRAP_H_ diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 286ea30a87cf31..b202b621dcb16e 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -10,6 +10,7 @@ #include "req-wrap.h" #include "req-wrap-inl.h" #include "stream_wrap.h" +#include "connection_wrap.h" #include "util-inl.h" #include "util.h" @@ -27,7 +28,6 @@ using v8::Integer; using v8::Local; using v8::Object; using v8::String; -using v8::Undefined; using v8::Value; @@ -162,49 +162,11 @@ void PipeWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - OnConnection); + ConnectionWrap::OnConnection); args.GetReturnValue().Set(err); } -// TODO(bnoordhuis) maybe share with TCPWrap? -void PipeWrap::OnConnection(uv_stream_t* handle, int status) { - PipeWrap* pipe_wrap = static_cast(handle->data); - CHECK_EQ(&pipe_wrap->handle_, reinterpret_cast(handle)); - - Environment* env = pipe_wrap->env(); - HandleScope handle_scope(env->isolate()); - Context::Scope context_scope(env->context()); - - // We should not be getting this callback if someone as already called - // uv_close() on the handle. - CHECK_EQ(pipe_wrap->persistent().IsEmpty(), false); - - Local argv[] = { - Integer::New(env->isolate(), status), - Undefined(env->isolate()) - }; - - if (status != 0) { - pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv); - return; - } - - // Instanciate the client javascript object and handle. - Local client_obj = Instantiate(env, pipe_wrap); - - // Unwrap the client javascript object. - PipeWrap* wrap; - ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); - uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); - if (uv_accept(handle, client_handle)) - return; - - // Successful accept. Call the onconnection callback in JavaScript land. - argv[1] = client_obj; - pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv); -} - // TODO(bnoordhuis) Maybe share this with TCPWrap? void PipeWrap::AfterConnect(uv_connect_t* req, int status) { PipeConnectWrap* req_wrap = static_cast(req->data); diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index f4784ac13a089f..b674e5d5d93ac9 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -6,10 +6,11 @@ #include "async-wrap.h" #include "env.h" #include "stream_wrap.h" +#include "connection_wrap.h" namespace node { -class PipeWrap : public StreamWrap { +class PipeWrap : public StreamWrap, ConnectionWrap { public: uv_pipe_t* UVHandle(); @@ -21,6 +22,7 @@ class PipeWrap : public StreamWrap { size_t self_size() const override { return sizeof(*this); } private: + friend class ConnectionWrap; // So handle_ can be accessed PipeWrap(Environment* env, v8::Local object, bool ipc, @@ -37,7 +39,6 @@ class PipeWrap : public StreamWrap { const v8::FunctionCallbackInfo& args); #endif - static void OnConnection(uv_stream_t* handle, int status); static void AfterConnect(uv_connect_t* req, int status); uv_pipe_t handle_; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 6904b27efd5e6e..cbd13d6b0e571f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -8,6 +8,7 @@ #include "req-wrap.h" #include "req-wrap-inl.h" #include "stream_wrap.h" +#include "connection_wrap.h" #include "util.h" #include "util-inl.h" @@ -28,7 +29,6 @@ using v8::Integer; using v8::Local; using v8::Object; using v8::String; -using v8::Undefined; using v8::Value; @@ -253,48 +253,11 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - OnConnection); + ConnectionWrap::OnConnection); args.GetReturnValue().Set(err); } -void TCPWrap::OnConnection(uv_stream_t* handle, int status) { - TCPWrap* tcp_wrap = static_cast(handle->data); - CHECK_EQ(&tcp_wrap->handle_, reinterpret_cast(handle)); - Environment* env = tcp_wrap->env(); - - HandleScope handle_scope(env->isolate()); - Context::Scope context_scope(env->context()); - - // We should not be getting this callback if someone as already called - // uv_close() on the handle. - CHECK_EQ(tcp_wrap->persistent().IsEmpty(), false); - - Local argv[2] = { - Integer::New(env->isolate(), status), - Undefined(env->isolate()) - }; - - if (status == 0) { - // Instantiate the client javascript object and handle. - Local client_obj = - Instantiate(env, static_cast(tcp_wrap)); - - // Unwrap the client javascript object. - TCPWrap* wrap = Unwrap(client_obj); - CHECK_NE(wrap, nullptr); - uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); - if (uv_accept(handle, client_handle)) - return; - - // Successful accept. Call the onconnection callback in JavaScript land. - argv[1] = client_obj; - } - - tcp_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv); -} - - void TCPWrap::AfterConnect(uv_connect_t* req, int status) { TCPConnectWrap* req_wrap = static_cast(req->data); TCPWrap* wrap = static_cast(req->handle->data); diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index af2d08d1ae80f4..137e337e0ba1d7 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -6,10 +6,11 @@ #include "async-wrap.h" #include "env.h" #include "stream_wrap.h" +#include "connection_wrap.h" namespace node { -class TCPWrap : public StreamWrap { +class TCPWrap : public StreamWrap, ConnectionWrap { public: static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, @@ -21,6 +22,7 @@ class TCPWrap : public StreamWrap { size_t self_size() const override { return sizeof(*this); } private: + friend class ConnectionWrap; // So handle_ can be accessed typedef uv_tcp_t HandleType; template & args); #endif - static void OnConnection(uv_stream_t* handle, int status); static void AfterConnect(uv_connect_t* req, int status); uv_tcp_t handle_; From a3b976e625c575eb4734a54d8907632e7a317ad5 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 7 Jul 2016 20:21:18 +0200 Subject: [PATCH 02/23] Moving template types to the ConnectionWrap class. --- src/connection_wrap.cc | 13 ++++++------- src/connection_wrap.h | 2 +- src/pipe_wrap.cc | 2 +- src/pipe_wrap.h | 2 +- src/tcp_wrap.cc | 2 +- src/tcp_wrap.h | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 88854fa5d51fcf..431854b86ae30c 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -18,7 +18,8 @@ using v8::Value; template -void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { +void ConnectionWrap::OnConnection(uv_stream_t* handle, + int status) { WrapType* wrap_data = static_cast(handle->data); CHECK_EQ(&wrap_data->handle_, reinterpret_cast(handle)); @@ -52,13 +53,11 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv); } -template void ConnectionWrap::OnConnection( - uv_stream_t* handle, - int status); +template void ConnectionWrap::OnConnection( + uv_stream_t* handle, int status); -template void ConnectionWrap::OnConnection( - uv_stream_t* handle, - int status); +template void ConnectionWrap::OnConnection( + uv_stream_t* handle, int status); } // namespace node diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 06b2dfcfcf8437..be4c4152c426fd 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -8,9 +8,9 @@ namespace node { +template class ConnectionWrap { protected: - template static void OnConnection(uv_stream_t* handle, int status); }; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index b202b621dcb16e..0e85096022ac61 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -162,7 +162,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - ConnectionWrap::OnConnection); + OnConnection); args.GetReturnValue().Set(err); } diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index b674e5d5d93ac9..7835e7d8de2984 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -10,7 +10,7 @@ namespace node { -class PipeWrap : public StreamWrap, ConnectionWrap { +class PipeWrap : public StreamWrap, ConnectionWrap { public: uv_pipe_t* UVHandle(); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index cbd13d6b0e571f..62fe8599dfad7f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -253,7 +253,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - ConnectionWrap::OnConnection); + OnConnection); args.GetReturnValue().Set(err); } diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index 137e337e0ba1d7..d64647d3717da7 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -10,7 +10,7 @@ namespace node { -class TCPWrap : public StreamWrap, ConnectionWrap { +class TCPWrap : public StreamWrap, ConnectionWrap { public: static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, From 34d5abc3a35de9ce7319b066e506d580b35a7d2e Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 8 Jul 2016 11:36:26 +0200 Subject: [PATCH 03/23] extracting UVHandle() and handle_ to ConnectionWrap. I originally just wanted to move the handle_ member from tcp_wrap and pipe_wrap without changing its name. But I ran into an issue which I believe is because tcp_wrap and pipe_wrap now extend ConnectionWrap. Both classes are derived from StreamWrap which has an inheritance tree that looks like this: class PipeWrap : public StreamWrap, ConnectionWrap class StreamWrap : public HandleWrap, public StreamBase class HandleWrap : public AsyncWrap class AsyncWrap : public BaseObject BaseObject has the following private member: v8::Persistent handle_; The compiler complains that 'handle_' is found in multiple base classes of different types: ../src/pipe_wrap.cc:130:50: error: member 'handle_' found in multiple base classes of different types reinterpret_cast(&handle_), ^ ../src/base-object.h:47:30: note: member found by ambiguous name lookup v8::Persistent handle_; It turns out that name lookup is performed before access rules are considered. C++ standard section 3.4: "The access rules (Clause 11) are considered only once name lookup and function overload resolution (if applicable) have succeeded." It is possible to be explicit about the type you want using the resolution operator ::. So we could use ConnectionWrap::handle_ to tell the compiler which type we want. But going down this route still caused changes to a number of files and I think the code is somewhat clearer using a different name for the handle, and there is no confusion with the handle_ member in BaseObject. Being fairly new to C++ and to the project there this is probably a gap in my knowledge about the best way to solve this. Looking forward to hear about other options/ideas for this. --- src/connection_wrap.cc | 14 ++++++++++++-- src/connection_wrap.h | 4 ++++ src/node_internals.h | 2 +- src/pipe_wrap.cc | 19 +++++++------------ src/pipe_wrap.h | 6 +----- src/tcp_wrap.cc | 27 +++++++++++---------------- src/tcp_wrap.h | 6 +----- src/udp_wrap.cc | 20 ++++++++++---------- src/udp_wrap.h | 2 +- 9 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 431854b86ae30c..402028f0ec92c5 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -21,7 +21,7 @@ template void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { WrapType* wrap_data = static_cast(handle->data); - CHECK_EQ(&wrap_data->handle_, reinterpret_cast(handle)); + CHECK_EQ(&wrap_data->uvhandle_, reinterpret_cast(handle)); Environment* env = wrap_data->env(); HandleScope handle_scope(env->isolate()); @@ -43,7 +43,8 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, // Unwrap the client javascript object. WrapType* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); - uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); + uv_stream_t* client_handle = + reinterpret_cast(&wrap->uvhandle_); if (uv_accept(handle, client_handle)) return; @@ -59,5 +60,14 @@ template void ConnectionWrap::OnConnection( template void ConnectionWrap::OnConnection( uv_stream_t* handle, int status); +template +UVType* ConnectionWrap::UVHandle() { + return &uvhandle_; +} + +template uv_pipe_t* ConnectionWrap::UVHandle(); + +template uv_tcp_t* ConnectionWrap::UVHandle(); + } // namespace node diff --git a/src/connection_wrap.h b/src/connection_wrap.h index be4c4152c426fd..1746a2189f1de4 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -10,8 +10,12 @@ namespace node { template class ConnectionWrap { + public: + UVType* UVHandle(); + protected: static void OnConnection(uv_stream_t* handle, int status); + UVType uvhandle_; }; diff --git a/src/node_internals.h b/src/node_internals.h index ff384231c12e0a..68089456ddedb1 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -86,7 +86,7 @@ void GetSockOrPeerName(const v8::FunctionCallbackInfo& args) { sockaddr_storage storage; int addrlen = sizeof(storage); sockaddr* const addr = reinterpret_cast(&storage); - const int err = F(&wrap->handle_, addr, &addrlen); + const int err = F(&wrap->uvhandle_, addr, &addrlen); if (err == 0) AddressToJS(wrap->env(), addr, args[0].As()); args.GetReturnValue().Set(err); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 0e85096022ac61..5cdf0495766006 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -51,11 +51,6 @@ static void NewPipeConnectWrap(const FunctionCallbackInfo& args) { } -uv_pipe_t* PipeWrap::UVHandle() { - return &handle_; -} - - Local PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) { EscapableHandleScope handle_scope(env->isolate()); CHECK_EQ(false, env->pipe_constructor_template().IsEmpty()); @@ -127,10 +122,10 @@ PipeWrap::PipeWrap(Environment* env, AsyncWrap* parent) : StreamWrap(env, object, - reinterpret_cast(&handle_), + reinterpret_cast(&uvhandle_), AsyncWrap::PROVIDER_PIPEWRAP, parent) { - int r = uv_pipe_init(env->event_loop(), &handle_, ipc); + int r = uv_pipe_init(env->event_loop(), &uvhandle_, ipc); CHECK_EQ(r, 0); // How do we proxy this error up to javascript? // Suggestion: uv_pipe_init() returns void. UpdateWriteQueueSize(); @@ -141,7 +136,7 @@ void PipeWrap::Bind(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); node::Utf8Value name(args.GetIsolate(), args[0]); - int err = uv_pipe_bind(&wrap->handle_, *name); + int err = uv_pipe_bind(&wrap->uvhandle_, *name); args.GetReturnValue().Set(err); } @@ -151,7 +146,7 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int instances = args[0]->Int32Value(); - uv_pipe_pending_instances(&wrap->handle_, instances); + uv_pipe_pending_instances(&wrap->uvhandle_, instances); } #endif @@ -160,7 +155,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int backlog = args[0]->Int32Value(); - int err = uv_listen(reinterpret_cast(&wrap->handle_), + int err = uv_listen(reinterpret_cast(&wrap->uvhandle_), backlog, OnConnection); args.GetReturnValue().Set(err); @@ -213,7 +208,7 @@ void PipeWrap::Open(const FunctionCallbackInfo& args) { int fd = args[0]->Int32Value(); - int err = uv_pipe_open(&wrap->handle_, fd); + int err = uv_pipe_open(&wrap->uvhandle_, fd); if (err != 0) env->isolate()->ThrowException(UVException(err, "uv_pipe_open")); @@ -234,7 +229,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { PipeConnectWrap* req_wrap = new PipeConnectWrap(env, req_wrap_obj); uv_pipe_connect(&req_wrap->req_, - &wrap->handle_, + &wrap->uvhandle_, *name, AfterConnect); req_wrap->Dispatched(); diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index 7835e7d8de2984..b815332dcf02e2 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -10,10 +10,8 @@ namespace node { -class PipeWrap : public StreamWrap, ConnectionWrap { +class PipeWrap : public StreamWrap, public ConnectionWrap { public: - uv_pipe_t* UVHandle(); - static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, v8::Local unused, @@ -40,8 +38,6 @@ class PipeWrap : public StreamWrap, ConnectionWrap { #endif static void AfterConnect(uv_connect_t* req, int status); - - uv_pipe_t handle_; }; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 62fe8599dfad7f..0a5d833898a7c1 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -121,11 +121,6 @@ void TCPWrap::Initialize(Local target, } -uv_tcp_t* TCPWrap::UVHandle() { - return &handle_; -} - - void TCPWrap::New(const FunctionCallbackInfo& args) { // This constructor should not be exposed to public javascript. // Therefore we assert that we are not trying to call this as a @@ -148,10 +143,10 @@ void TCPWrap::New(const FunctionCallbackInfo& args) { TCPWrap::TCPWrap(Environment* env, Local object, AsyncWrap* parent) : StreamWrap(env, object, - reinterpret_cast(&handle_), + reinterpret_cast(&uvhandle_), AsyncWrap::PROVIDER_TCPWRAP, parent) { - int r = uv_tcp_init(env->event_loop(), &handle_); + int r = uv_tcp_init(env->event_loop(), &uvhandle_); CHECK_EQ(r, 0); // How do we proxy this error up to javascript? // Suggestion: uv_tcp_init() returns void. UpdateWriteQueueSize(); @@ -169,7 +164,7 @@ void TCPWrap::SetNoDelay(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int enable = static_cast(args[0]->BooleanValue()); - int err = uv_tcp_nodelay(&wrap->handle_, enable); + int err = uv_tcp_nodelay(&wrap->uvhandle_, enable); args.GetReturnValue().Set(err); } @@ -181,7 +176,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(UV_EBADF)); int enable = args[0]->Int32Value(); unsigned int delay = args[1]->Uint32Value(); - int err = uv_tcp_keepalive(&wrap->handle_, enable, delay); + int err = uv_tcp_keepalive(&wrap->uvhandle_, enable, delay); args.GetReturnValue().Set(err); } @@ -193,7 +188,7 @@ void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); bool enable = args[0]->BooleanValue(); - int err = uv_tcp_simultaneous_accepts(&wrap->handle_, enable); + int err = uv_tcp_simultaneous_accepts(&wrap->uvhandle_, enable); args.GetReturnValue().Set(err); } #endif @@ -205,7 +200,7 @@ void TCPWrap::Open(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int fd = static_cast(args[0]->IntegerValue()); - uv_tcp_open(&wrap->handle_, fd); + uv_tcp_open(&wrap->uvhandle_, fd); } @@ -219,7 +214,7 @@ void TCPWrap::Bind(const FunctionCallbackInfo& args) { sockaddr_in addr; int err = uv_ip4_addr(*ip_address, port, &addr); if (err == 0) { - err = uv_tcp_bind(&wrap->handle_, + err = uv_tcp_bind(&wrap->uvhandle_, reinterpret_cast(&addr), 0); } @@ -237,7 +232,7 @@ void TCPWrap::Bind6(const FunctionCallbackInfo& args) { sockaddr_in6 addr; int err = uv_ip6_addr(*ip6_address, port, &addr); if (err == 0) { - err = uv_tcp_bind(&wrap->handle_, + err = uv_tcp_bind(&wrap->uvhandle_, reinterpret_cast(&addr), 0); } @@ -251,7 +246,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int backlog = args[0]->Int32Value(); - int err = uv_listen(reinterpret_cast(&wrap->handle_), + int err = uv_listen(reinterpret_cast(&wrap->uvhandle_), backlog, OnConnection); args.GetReturnValue().Set(err); @@ -308,7 +303,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args) { if (err == 0) { TCPConnectWrap* req_wrap = new TCPConnectWrap(env, req_wrap_obj); err = uv_tcp_connect(&req_wrap->req_, - &wrap->handle_, + &wrap->uvhandle_, reinterpret_cast(&addr), AfterConnect); req_wrap->Dispatched(); @@ -342,7 +337,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo& args) { if (err == 0) { TCPConnectWrap* req_wrap = new TCPConnectWrap(env, req_wrap_obj); err = uv_tcp_connect(&req_wrap->req_, - &wrap->handle_, + &wrap->uvhandle_, reinterpret_cast(&addr), AfterConnect); req_wrap->Dispatched(); diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index d64647d3717da7..fc2b22f609913f 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -10,15 +10,13 @@ namespace node { -class TCPWrap : public StreamWrap, ConnectionWrap { +class TCPWrap : public StreamWrap, public ConnectionWrap { public: static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, v8::Local unused, v8::Local context); - uv_tcp_t* UVHandle(); - size_t self_size() const override { return sizeof(*this); } private: @@ -48,8 +46,6 @@ class TCPWrap : public StreamWrap, ConnectionWrap { #endif static void AfterConnect(uv_connect_t* req, int status); - - uv_tcp_t handle_; }; diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index bd7aa418bd89cf..547727963ef131 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -65,9 +65,9 @@ static void NewSendWrap(const FunctionCallbackInfo& args) { UDPWrap::UDPWrap(Environment* env, Local object, AsyncWrap* parent) : HandleWrap(env, object, - reinterpret_cast(&handle_), + reinterpret_cast(&uvhandle_), AsyncWrap::PROVIDER_UDPWRAP) { - int r = uv_udp_init(env->event_loop(), &handle_); + int r = uv_udp_init(env->event_loop(), &uvhandle_); CHECK_EQ(r, 0); // can't fail anyway } @@ -144,7 +144,7 @@ void UDPWrap::GetFD(Local, const PropertyCallbackInfo& args) { HandleScope scope(args.GetIsolate()); UDPWrap* wrap = Unwrap(args.Holder()); if (wrap != nullptr) - uv_fileno(reinterpret_cast(&wrap->handle_), &fd); + uv_fileno(reinterpret_cast(&wrap->uvhandle_), &fd); #endif args.GetReturnValue().Set(fd); } @@ -178,7 +178,7 @@ void UDPWrap::DoBind(const FunctionCallbackInfo& args, int family) { } if (err == 0) { - err = uv_udp_bind(&wrap->handle_, + err = uv_udp_bind(&wrap->uvhandle_, reinterpret_cast(&addr), flags); } @@ -202,7 +202,7 @@ void UDPWrap::Bind6(const FunctionCallbackInfo& args) { UDPWrap* wrap = Unwrap(args.Holder()); \ CHECK_EQ(args.Length(), 1); \ int flag = args[0]->Int32Value(); \ - int err = wrap == nullptr ? UV_EBADF : fn(&wrap->handle_, flag); \ + int err = wrap == nullptr ? UV_EBADF : fn(&wrap->uvhandle_, flag); \ args.GetReturnValue().Set(err); \ } @@ -231,7 +231,7 @@ void UDPWrap::SetMembership(const FunctionCallbackInfo& args, iface_cstr = nullptr; } - int err = uv_udp_set_membership(&wrap->handle_, + int err = uv_udp_set_membership(&wrap->uvhandle_, *address, iface_cstr, membership); @@ -314,7 +314,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { if (err == 0) { err = uv_udp_send(&req_wrap->req_, - &wrap->handle_, + &wrap->uvhandle_, bufs, count, reinterpret_cast(&addr), @@ -348,7 +348,7 @@ void UDPWrap::RecvStart(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); - int err = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv); + int err = uv_udp_recv_start(&wrap->uvhandle_, OnAlloc, OnRecv); // UV_EALREADY means that the socket is already bound but that's okay if (err == UV_EALREADY) err = 0; @@ -361,7 +361,7 @@ void UDPWrap::RecvStop(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); - int r = uv_udp_recv_stop(&wrap->handle_); + int r = uv_udp_recv_stop(&wrap->uvhandle_); args.GetReturnValue().Set(r); } @@ -446,7 +446,7 @@ Local UDPWrap::Instantiate(Environment* env, AsyncWrap* parent) { uv_udp_t* UDPWrap::UVHandle() { - return &handle_; + return &uvhandle_; } diff --git a/src/udp_wrap.h b/src/udp_wrap.h index 0d33e617c0e4b8..91f98b1ab1c026 100644 --- a/src/udp_wrap.h +++ b/src/udp_wrap.h @@ -67,7 +67,7 @@ class UDPWrap: public HandleWrap { const struct sockaddr* addr, unsigned int flags); - uv_udp_t handle_; + uv_udp_t uvhandle_; }; } // namespace node From 564342d3924ac0e8d3577c0f2eef92014de03648 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 13:24:55 +0200 Subject: [PATCH 04/23] Renaming BaseObject's handle_ to objecthandle_ --- src/base-object-inl.h | 14 +++++++------- src/base-object.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/base-object-inl.h b/src/base-object-inl.h index b4c3730f1ae870..e9cfdb90547d64 100644 --- a/src/base-object-inl.h +++ b/src/base-object-inl.h @@ -13,7 +13,7 @@ namespace node { inline BaseObject::BaseObject(Environment* env, v8::Local handle) - : handle_(env->isolate(), handle), + : objecthandle_(env->isolate(), handle), env_(env) { CHECK_EQ(false, handle.IsEmpty()); // The zero field holds a pointer to the handle. Immediately set it to @@ -24,17 +24,17 @@ inline BaseObject::BaseObject(Environment* env, v8::Local handle) inline BaseObject::~BaseObject() { - CHECK(handle_.IsEmpty()); + CHECK(objecthandle_.IsEmpty()); } inline v8::Persistent& BaseObject::persistent() { - return handle_; + return objecthandle_; } inline v8::Local BaseObject::object() { - return PersistentToLocal(env_->isolate(), handle_); + return PersistentToLocal(env_->isolate(), objecthandle_); } @@ -58,14 +58,14 @@ inline void BaseObject::MakeWeak(Type* ptr) { v8::Local handle = object(); CHECK_GT(handle->InternalFieldCount(), 0); Wrap(handle, ptr); - handle_.MarkIndependent(); - handle_.SetWeak(ptr, WeakCallback, + objecthandle_.MarkIndependent(); + objecthandle_.SetWeak(ptr, WeakCallback, v8::WeakCallbackType::kParameter); } inline void BaseObject::ClearWeak() { - handle_.ClearWeak(); + objecthandle_.ClearWeak(); } } // namespace node diff --git a/src/base-object.h b/src/base-object.h index afec3442ce84b5..d6b09042abb28c 100644 --- a/src/base-object.h +++ b/src/base-object.h @@ -44,7 +44,7 @@ class BaseObject { static inline void WeakCallback( const v8::WeakCallbackInfo& data); - v8::Persistent handle_; + v8::Persistent objecthandle_; Environment* env_; }; From 623ad2e9fe72331648f91ca90e6ef715e8c7ab19 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 13:32:10 +0200 Subject: [PATCH 05/23] Changing uvhandle_ back to handle_ --- src/connection_wrap.cc | 4 ++-- src/connection_wrap.h | 2 +- src/node_internals.h | 2 +- src/pipe_wrap.cc | 14 +++++++------- src/tcp_wrap.cc | 22 +++++++++++----------- src/udp_wrap.cc | 20 ++++++++++---------- src/udp_wrap.h | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 402028f0ec92c5..0b8a20bed29938 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -21,7 +21,7 @@ template void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { WrapType* wrap_data = static_cast(handle->data); - CHECK_EQ(&wrap_data->uvhandle_, reinterpret_cast(handle)); + CHECK_EQ(&wrap_data->handle_, reinterpret_cast(handle)); Environment* env = wrap_data->env(); HandleScope handle_scope(env->isolate()); @@ -44,7 +44,7 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, WrapType* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); uv_stream_t* client_handle = - reinterpret_cast(&wrap->uvhandle_); + reinterpret_cast(&wrap->handle_); if (uv_accept(handle, client_handle)) return; diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 1746a2189f1de4..4a80f6f9b48ceb 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -15,7 +15,7 @@ class ConnectionWrap { protected: static void OnConnection(uv_stream_t* handle, int status); - UVType uvhandle_; + UVType handle_; }; diff --git a/src/node_internals.h b/src/node_internals.h index 68089456ddedb1..ff384231c12e0a 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -86,7 +86,7 @@ void GetSockOrPeerName(const v8::FunctionCallbackInfo& args) { sockaddr_storage storage; int addrlen = sizeof(storage); sockaddr* const addr = reinterpret_cast(&storage); - const int err = F(&wrap->uvhandle_, addr, &addrlen); + const int err = F(&wrap->handle_, addr, &addrlen); if (err == 0) AddressToJS(wrap->env(), addr, args[0].As()); args.GetReturnValue().Set(err); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 5cdf0495766006..cefbe25253a1fd 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -122,10 +122,10 @@ PipeWrap::PipeWrap(Environment* env, AsyncWrap* parent) : StreamWrap(env, object, - reinterpret_cast(&uvhandle_), + reinterpret_cast(&handle_), AsyncWrap::PROVIDER_PIPEWRAP, parent) { - int r = uv_pipe_init(env->event_loop(), &uvhandle_, ipc); + int r = uv_pipe_init(env->event_loop(), &handle_, ipc); CHECK_EQ(r, 0); // How do we proxy this error up to javascript? // Suggestion: uv_pipe_init() returns void. UpdateWriteQueueSize(); @@ -136,7 +136,7 @@ void PipeWrap::Bind(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); node::Utf8Value name(args.GetIsolate(), args[0]); - int err = uv_pipe_bind(&wrap->uvhandle_, *name); + int err = uv_pipe_bind(&wrap->handle_, *name); args.GetReturnValue().Set(err); } @@ -146,7 +146,7 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int instances = args[0]->Int32Value(); - uv_pipe_pending_instances(&wrap->uvhandle_, instances); + uv_pipe_pending_instances(&wrap->handle_, instances); } #endif @@ -155,7 +155,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int backlog = args[0]->Int32Value(); - int err = uv_listen(reinterpret_cast(&wrap->uvhandle_), + int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, OnConnection); args.GetReturnValue().Set(err); @@ -208,7 +208,7 @@ void PipeWrap::Open(const FunctionCallbackInfo& args) { int fd = args[0]->Int32Value(); - int err = uv_pipe_open(&wrap->uvhandle_, fd); + int err = uv_pipe_open(&wrap->handle_, fd); if (err != 0) env->isolate()->ThrowException(UVException(err, "uv_pipe_open")); @@ -229,7 +229,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { PipeConnectWrap* req_wrap = new PipeConnectWrap(env, req_wrap_obj); uv_pipe_connect(&req_wrap->req_, - &wrap->uvhandle_, + &wrap->handle_, *name, AfterConnect); req_wrap->Dispatched(); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 0a5d833898a7c1..9ee422bbc4d769 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -143,10 +143,10 @@ void TCPWrap::New(const FunctionCallbackInfo& args) { TCPWrap::TCPWrap(Environment* env, Local object, AsyncWrap* parent) : StreamWrap(env, object, - reinterpret_cast(&uvhandle_), + reinterpret_cast(&handle_), AsyncWrap::PROVIDER_TCPWRAP, parent) { - int r = uv_tcp_init(env->event_loop(), &uvhandle_); + int r = uv_tcp_init(env->event_loop(), &handle_); CHECK_EQ(r, 0); // How do we proxy this error up to javascript? // Suggestion: uv_tcp_init() returns void. UpdateWriteQueueSize(); @@ -164,7 +164,7 @@ void TCPWrap::SetNoDelay(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int enable = static_cast(args[0]->BooleanValue()); - int err = uv_tcp_nodelay(&wrap->uvhandle_, enable); + int err = uv_tcp_nodelay(&wrap->handle_, enable); args.GetReturnValue().Set(err); } @@ -176,7 +176,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(UV_EBADF)); int enable = args[0]->Int32Value(); unsigned int delay = args[1]->Uint32Value(); - int err = uv_tcp_keepalive(&wrap->uvhandle_, enable, delay); + int err = uv_tcp_keepalive(&wrap->handle_, enable, delay); args.GetReturnValue().Set(err); } @@ -188,7 +188,7 @@ void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); bool enable = args[0]->BooleanValue(); - int err = uv_tcp_simultaneous_accepts(&wrap->uvhandle_, enable); + int err = uv_tcp_simultaneous_accepts(&wrap->handle_, enable); args.GetReturnValue().Set(err); } #endif @@ -200,7 +200,7 @@ void TCPWrap::Open(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int fd = static_cast(args[0]->IntegerValue()); - uv_tcp_open(&wrap->uvhandle_, fd); + uv_tcp_open(&wrap->handle_, fd); } @@ -214,7 +214,7 @@ void TCPWrap::Bind(const FunctionCallbackInfo& args) { sockaddr_in addr; int err = uv_ip4_addr(*ip_address, port, &addr); if (err == 0) { - err = uv_tcp_bind(&wrap->uvhandle_, + err = uv_tcp_bind(&wrap->handle_, reinterpret_cast(&addr), 0); } @@ -232,7 +232,7 @@ void TCPWrap::Bind6(const FunctionCallbackInfo& args) { sockaddr_in6 addr; int err = uv_ip6_addr(*ip6_address, port, &addr); if (err == 0) { - err = uv_tcp_bind(&wrap->uvhandle_, + err = uv_tcp_bind(&wrap->handle_, reinterpret_cast(&addr), 0); } @@ -246,7 +246,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int backlog = args[0]->Int32Value(); - int err = uv_listen(reinterpret_cast(&wrap->uvhandle_), + int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, OnConnection); args.GetReturnValue().Set(err); @@ -303,7 +303,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args) { if (err == 0) { TCPConnectWrap* req_wrap = new TCPConnectWrap(env, req_wrap_obj); err = uv_tcp_connect(&req_wrap->req_, - &wrap->uvhandle_, + &wrap->handle_, reinterpret_cast(&addr), AfterConnect); req_wrap->Dispatched(); @@ -337,7 +337,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo& args) { if (err == 0) { TCPConnectWrap* req_wrap = new TCPConnectWrap(env, req_wrap_obj); err = uv_tcp_connect(&req_wrap->req_, - &wrap->uvhandle_, + &wrap->handle_, reinterpret_cast(&addr), AfterConnect); req_wrap->Dispatched(); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 547727963ef131..83ef4f45a38025 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -65,9 +65,9 @@ static void NewSendWrap(const FunctionCallbackInfo& args) { UDPWrap::UDPWrap(Environment* env, Local object, AsyncWrap* parent) : HandleWrap(env, object, - reinterpret_cast(&uvhandle_), + reinterpret_cast(&handle_), AsyncWrap::PROVIDER_UDPWRAP) { - int r = uv_udp_init(env->event_loop(), &uvhandle_); + int r = uv_udp_init(env->event_loop(), &handle_); CHECK_EQ(r, 0); // can't fail anyway } @@ -144,7 +144,7 @@ void UDPWrap::GetFD(Local, const PropertyCallbackInfo& args) { HandleScope scope(args.GetIsolate()); UDPWrap* wrap = Unwrap(args.Holder()); if (wrap != nullptr) - uv_fileno(reinterpret_cast(&wrap->uvhandle_), &fd); + uv_fileno(reinterpret_cast(&wrap->handle_), &fd); #endif args.GetReturnValue().Set(fd); } @@ -178,7 +178,7 @@ void UDPWrap::DoBind(const FunctionCallbackInfo& args, int family) { } if (err == 0) { - err = uv_udp_bind(&wrap->uvhandle_, + err = uv_udp_bind(&wrap->handle_, reinterpret_cast(&addr), flags); } @@ -202,7 +202,7 @@ void UDPWrap::Bind6(const FunctionCallbackInfo& args) { UDPWrap* wrap = Unwrap(args.Holder()); \ CHECK_EQ(args.Length(), 1); \ int flag = args[0]->Int32Value(); \ - int err = wrap == nullptr ? UV_EBADF : fn(&wrap->uvhandle_, flag); \ + int err = wrap == nullptr ? UV_EBADF : fn(&wrap->handle_, flag); \ args.GetReturnValue().Set(err); \ } @@ -231,7 +231,7 @@ void UDPWrap::SetMembership(const FunctionCallbackInfo& args, iface_cstr = nullptr; } - int err = uv_udp_set_membership(&wrap->uvhandle_, + int err = uv_udp_set_membership(&wrap->handle_, *address, iface_cstr, membership); @@ -314,7 +314,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { if (err == 0) { err = uv_udp_send(&req_wrap->req_, - &wrap->uvhandle_, + &wrap->handle_, bufs, count, reinterpret_cast(&addr), @@ -348,7 +348,7 @@ void UDPWrap::RecvStart(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); - int err = uv_udp_recv_start(&wrap->uvhandle_, OnAlloc, OnRecv); + int err = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv); // UV_EALREADY means that the socket is already bound but that's okay if (err == UV_EALREADY) err = 0; @@ -361,7 +361,7 @@ void UDPWrap::RecvStop(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); - int r = uv_udp_recv_stop(&wrap->uvhandle_); + int r = uv_udp_recv_stop(&wrap->handle_); args.GetReturnValue().Set(r); } @@ -446,7 +446,7 @@ Local UDPWrap::Instantiate(Environment* env, AsyncWrap* parent) { uv_udp_t* UDPWrap::UVHandle() { - return &uvhandle_; + return &handle_; } diff --git a/src/udp_wrap.h b/src/udp_wrap.h index 91f98b1ab1c026..0d33e617c0e4b8 100644 --- a/src/udp_wrap.h +++ b/src/udp_wrap.h @@ -67,7 +67,7 @@ class UDPWrap: public HandleWrap { const struct sockaddr* addr, unsigned int flags); - uv_udp_t uvhandle_; + uv_udp_t handle_; }; } // namespace node From 458accca860adbe8efd25c3d68b10d1552de8c0d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 13:33:58 +0200 Subject: [PATCH 06/23] Removing unnecessary friend class ConnectionWrap --- src/pipe_wrap.h | 1 - src/tcp_wrap.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index b815332dcf02e2..5874887e9cfce5 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -20,7 +20,6 @@ class PipeWrap : public StreamWrap, public ConnectionWrap { size_t self_size() const override { return sizeof(*this); } private: - friend class ConnectionWrap; // So handle_ can be accessed PipeWrap(Environment* env, v8::Local object, bool ipc, diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index fc2b22f609913f..9a37ff0d9c1c6e 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -20,7 +20,6 @@ class TCPWrap : public StreamWrap, public ConnectionWrap { size_t self_size() const override { return sizeof(*this); } private: - friend class ConnectionWrap; // So handle_ can be accessed typedef uv_tcp_t HandleType; template Date: Sat, 9 Jul 2016 13:39:56 +0200 Subject: [PATCH 07/23] Making UVHandle() an inline member function. --- src/connection_wrap.cc | 5 ----- src/connection_wrap.h | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 0b8a20bed29938..7bef8d654270ba 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -60,11 +60,6 @@ template void ConnectionWrap::OnConnection( template void ConnectionWrap::OnConnection( uv_stream_t* handle, int status); -template -UVType* ConnectionWrap::UVHandle() { - return &uvhandle_; -} - template uv_pipe_t* ConnectionWrap::UVHandle(); template uv_tcp_t* ConnectionWrap::UVHandle(); diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 4a80f6f9b48ceb..27dc7411661d25 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -11,7 +11,9 @@ namespace node { template class ConnectionWrap { public: - UVType* UVHandle(); + UVType* UVHandle() { + return &handle_; + } protected: static void OnConnection(uv_stream_t* handle, int status); From 5562c45c32316429bfc165a80c71cde5ac5ee87c Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 13:44:40 +0200 Subject: [PATCH 08/23] Adding a space after template keyword --- src/connection_wrap.cc | 2 +- src/connection_wrap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 7bef8d654270ba..d1ae55c7a03617 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -17,7 +17,7 @@ using v8::Object; using v8::Value; -template +template void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { WrapType* wrap_data = static_cast(handle->data); diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 27dc7411661d25..3650a7422825ab 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -8,7 +8,7 @@ namespace node { -template +template class ConnectionWrap { public: UVType* UVHandle() { From ee62109f17d1e44b742fc84b5828807772827186 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 13:46:57 +0200 Subject: [PATCH 09/23] Correcting comment changing Instanciate to Instantiate --- src/connection_wrap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index d1ae55c7a03617..f4338abbcbddc2 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -37,7 +37,7 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, }; if (status == 0) { - // Instanciate the client javascript object and handle. + // Instantiate the client javascript object and handle. Local client_obj = WrapType::Instantiate(env, wrap_data); // Unwrap the client javascript object. From 579f48a60ac5e2c6b9d92255e58b3a0b92e8d632 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 13:53:46 +0200 Subject: [PATCH 10/23] Adding a null pointer check for wrap_data. --- src/connection_wrap.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index f4338abbcbddc2..0196583a10df87 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -21,6 +21,7 @@ template void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { WrapType* wrap_data = static_cast(handle->data); + CHECK_NE(wrap_data, nullptr); CHECK_EQ(&wrap_data->handle_, reinterpret_cast(handle)); Environment* env = wrap_data->env(); From 1437ec6a9c5a2ac3cb0c0bc127822e40b4e95c02 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 14:57:29 +0200 Subject: [PATCH 11/23] Adding back spaces to line up macro continuation escape charaters --- src/udp_wrap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 83ef4f45a38025..bd7aa418bd89cf 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -202,7 +202,7 @@ void UDPWrap::Bind6(const FunctionCallbackInfo& args) { UDPWrap* wrap = Unwrap(args.Holder()); \ CHECK_EQ(args.Length(), 1); \ int flag = args[0]->Int32Value(); \ - int err = wrap == nullptr ? UV_EBADF : fn(&wrap->handle_, flag); \ + int err = wrap == nullptr ? UV_EBADF : fn(&wrap->handle_, flag); \ args.GetReturnValue().Set(err); \ } From d0da4bc54d56e42ff217aeee1648b9fbaa1de981 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 15:05:34 +0200 Subject: [PATCH 12/23] Removing unnecessary template specializations --- src/connection_wrap.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 0196583a10df87..814cc1296628b6 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -61,9 +61,5 @@ template void ConnectionWrap::OnConnection( template void ConnectionWrap::OnConnection( uv_stream_t* handle, int status); -template uv_pipe_t* ConnectionWrap::UVHandle(); - -template uv_tcp_t* ConnectionWrap::UVHandle(); - } // namespace node From 1b3be6003d60b1d4df59e315abf77f219ec8d18a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 9 Jul 2016 15:17:43 +0200 Subject: [PATCH 13/23] Fixing typo in comment. --- src/connection_wrap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 814cc1296628b6..4253fbd444391c 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -28,7 +28,7 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - // We should not be getting this callback if someone as already called + // We should not be getting this callback if someone has already called // uv_close() on the handle. CHECK_EQ(wrap_data->persistent().IsEmpty(), false); From e364ec463acecf9353d770783f83086401835df0 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 14 Jul 2016 18:00:02 +0200 Subject: [PATCH 14/23] Lining up arguments for SetWeak method call --- src/base-object-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base-object-inl.h b/src/base-object-inl.h index e9cfdb90547d64..2112048c24a75f 100644 --- a/src/base-object-inl.h +++ b/src/base-object-inl.h @@ -60,7 +60,7 @@ inline void BaseObject::MakeWeak(Type* ptr) { Wrap(handle, ptr); objecthandle_.MarkIndependent(); objecthandle_.SetWeak(ptr, WeakCallback, - v8::WeakCallbackType::kParameter); + v8::WeakCallbackType::kParameter); } From e8ed621525fb66c233e4aca882904c2d77b0d962 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 14 Jul 2016 18:10:12 +0200 Subject: [PATCH 15/23] Renaming objecthandle_ to persistent_handle_ --- src/base-object-inl.h | 16 ++++++++-------- src/base-object.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/base-object-inl.h b/src/base-object-inl.h index 2112048c24a75f..4ddc5e1349bc13 100644 --- a/src/base-object-inl.h +++ b/src/base-object-inl.h @@ -13,7 +13,7 @@ namespace node { inline BaseObject::BaseObject(Environment* env, v8::Local handle) - : objecthandle_(env->isolate(), handle), + : persistent_handle_(env->isolate(), handle), env_(env) { CHECK_EQ(false, handle.IsEmpty()); // The zero field holds a pointer to the handle. Immediately set it to @@ -24,17 +24,17 @@ inline BaseObject::BaseObject(Environment* env, v8::Local handle) inline BaseObject::~BaseObject() { - CHECK(objecthandle_.IsEmpty()); + CHECK(persistent_handle_.IsEmpty()); } inline v8::Persistent& BaseObject::persistent() { - return objecthandle_; + return persistent_handle_; } inline v8::Local BaseObject::object() { - return PersistentToLocal(env_->isolate(), objecthandle_); + return PersistentToLocal(env_->isolate(), persistent_handle_); } @@ -58,14 +58,14 @@ inline void BaseObject::MakeWeak(Type* ptr) { v8::Local handle = object(); CHECK_GT(handle->InternalFieldCount(), 0); Wrap(handle, ptr); - objecthandle_.MarkIndependent(); - objecthandle_.SetWeak(ptr, WeakCallback, - v8::WeakCallbackType::kParameter); + persistent_handle_.MarkIndependent(); + persistent_handle_.SetWeak(ptr, WeakCallback, + v8::WeakCallbackType::kParameter); } inline void BaseObject::ClearWeak() { - objecthandle_.ClearWeak(); + persistent_handle_.ClearWeak(); } } // namespace node diff --git a/src/base-object.h b/src/base-object.h index d6b09042abb28c..27251379770e2c 100644 --- a/src/base-object.h +++ b/src/base-object.h @@ -44,7 +44,7 @@ class BaseObject { static inline void WeakCallback( const v8::WeakCallbackInfo& data); - v8::Persistent objecthandle_; + v8::Persistent persistent_handle_; Environment* env_; }; From 7ce112abafded06592cf88017d9cfda58c2ab6fb Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 14 Jul 2016 18:32:49 +0200 Subject: [PATCH 16/23] Adding a comment to clarify uv_accept error handling --- src/connection_wrap.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index 4253fbd444391c..ffd78c90a8df89 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -46,6 +46,9 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); + // uv_accept can fail if the new connection has already been closed, in + // which case an EAGAIN (resource temporarily unavailabile) will be + // returned. if (uv_accept(handle, client_handle)) return; From c9ec24d72190cfd63cfa97ce1ce338de56f3cde3 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 14 Jul 2016 18:40:37 +0200 Subject: [PATCH 17/23] Correcting spelling of unavailable. --- src/connection_wrap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index ffd78c90a8df89..b95a0c091cc39d 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -47,7 +47,7 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); // uv_accept can fail if the new connection has already been closed, in - // which case an EAGAIN (resource temporarily unavailabile) will be + // which case an EAGAIN (resource temporarily unavailable) will be // returned. if (uv_accept(handle, client_handle)) return; From 5ef85f9eb2eb125cf65adf57ced3a7f3ee61e886 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 14 Jul 2016 20:57:38 +0200 Subject: [PATCH 18/23] Removing multiple inheritance. --- src/connection_wrap.h | 6 ------ src/pipe_wrap.cc | 2 +- src/pipe_wrap.h | 8 +++++++- src/tcp_wrap.cc | 2 +- src/tcp_wrap.h | 8 +++++++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 3650a7422825ab..44f0e1e14477cb 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -11,13 +11,7 @@ namespace node { template class ConnectionWrap { public: - UVType* UVHandle() { - return &handle_; - } - - protected: static void OnConnection(uv_stream_t* handle, int status); - UVType handle_; }; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index cefbe25253a1fd..b0949da9f6dd45 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -157,7 +157,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - OnConnection); + ConnectionWrap::OnConnection); args.GetReturnValue().Set(err); } diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index 5874887e9cfce5..d2890ce177eb3b 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -10,8 +10,11 @@ namespace node { -class PipeWrap : public StreamWrap, public ConnectionWrap { +class PipeWrap : public StreamWrap { public: + uv_pipe_t* UVHandle() { + return &handle_; + } static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, v8::Local unused, @@ -20,6 +23,7 @@ class PipeWrap : public StreamWrap, public ConnectionWrap { size_t self_size() const override { return sizeof(*this); } private: + friend class ConnectionWrap; PipeWrap(Environment* env, v8::Local object, bool ipc, @@ -37,6 +41,8 @@ class PipeWrap : public StreamWrap, public ConnectionWrap { #endif static void AfterConnect(uv_connect_t* req, int status); + + uv_pipe_t handle_; }; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 9ee422bbc4d769..78aaf1156625a1 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -248,7 +248,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - OnConnection); + ConnectionWrap::OnConnection); args.GetReturnValue().Set(err); } diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index 9a37ff0d9c1c6e..d20a329e8d9ad6 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -10,8 +10,11 @@ namespace node { -class TCPWrap : public StreamWrap, public ConnectionWrap { +class TCPWrap : public StreamWrap { public: + uv_tcp_t* UVHandle() { + return &handle_; + } static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, v8::Local unused, @@ -20,6 +23,7 @@ class TCPWrap : public StreamWrap, public ConnectionWrap { size_t self_size() const override { return sizeof(*this); } private: + friend class ConnectionWrap; typedef uv_tcp_t HandleType; template { #endif static void AfterConnect(uv_connect_t* req, int status); + + uv_tcp_t handle_; }; From ece2d31a62a75833ce94f130e3848b02b6d7cc53 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 16 Jul 2016 21:10:32 +0200 Subject: [PATCH 19/23] Making ConnectionWrap inherit from StreamWrap --- src/connection_wrap.cc | 25 +++++++++++++++++++++++++ src/connection_wrap.h | 16 +++++++++++++++- src/pipe_wrap.cc | 11 +++++------ src/pipe_wrap.h | 11 ++--------- src/tcp_wrap.cc | 11 +++++------ src/tcp_wrap.h | 9 +-------- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index b95a0c091cc39d..f98fb79eb910c6 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -3,6 +3,7 @@ #include "env-inl.h" #include "env.h" #include "pipe_wrap.h" +#include "stream_wrap.h" #include "tcp_wrap.h" #include "util.h" #include "util-inl.h" @@ -17,6 +18,18 @@ using v8::Object; using v8::Value; +template +ConnectionWrap::ConnectionWrap(Environment* env, + Local object, + ProviderType provider, + AsyncWrap* parent) + : StreamWrap(env, + object, + reinterpret_cast(&handle_), + provider, + parent) {} + + template void ConnectionWrap::OnConnection(uv_stream_t* handle, int status) { @@ -58,6 +71,18 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv); } +template ConnectionWrap::ConnectionWrap( + Environment* env, + Local object, + ProviderType provider, + AsyncWrap* parent); + +template ConnectionWrap::ConnectionWrap( + Environment* env, + Local object, + ProviderType provider, + AsyncWrap* parent); + template void ConnectionWrap::OnConnection( uv_stream_t* handle, int status); diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 44f0e1e14477cb..40842f224d327f 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -3,15 +3,29 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS +#include "async-wrap.h" #include "env.h" +#include "stream_wrap.h" #include "v8.h" namespace node { template -class ConnectionWrap { +class ConnectionWrap : public StreamWrap { public: + UVType* UVHandle() { + return &handle_; + } + static void OnConnection(uv_stream_t* handle, int status); + + protected: + ConnectionWrap(Environment* env, + v8::Local object, + ProviderType provider, + AsyncWrap* parent); + + UVType handle_; }; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index b0949da9f6dd45..cf14e49753227f 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -1,6 +1,7 @@ #include "pipe_wrap.h" #include "async-wrap.h" +#include "connection_wrap.h" #include "env.h" #include "env-inl.h" #include "handle_wrap.h" @@ -10,7 +11,6 @@ #include "req-wrap.h" #include "req-wrap-inl.h" #include "stream_wrap.h" -#include "connection_wrap.h" #include "util-inl.h" #include "util.h" @@ -120,11 +120,10 @@ PipeWrap::PipeWrap(Environment* env, Local object, bool ipc, AsyncWrap* parent) - : StreamWrap(env, - object, - reinterpret_cast(&handle_), - AsyncWrap::PROVIDER_PIPEWRAP, - parent) { + : ConnectionWrap(env, + object, + AsyncWrap::PROVIDER_PIPEWRAP, + parent) { int r = uv_pipe_init(env->event_loop(), &handle_, ipc); CHECK_EQ(r, 0); // How do we proxy this error up to javascript? // Suggestion: uv_pipe_init() returns void. diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index d2890ce177eb3b..1e11221abc5d8b 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -4,17 +4,13 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "async-wrap.h" -#include "env.h" -#include "stream_wrap.h" #include "connection_wrap.h" +#include "env.h" namespace node { -class PipeWrap : public StreamWrap { +class PipeWrap : public ConnectionWrap { public: - uv_pipe_t* UVHandle() { - return &handle_; - } static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, v8::Local unused, @@ -23,7 +19,6 @@ class PipeWrap : public StreamWrap { size_t self_size() const override { return sizeof(*this); } private: - friend class ConnectionWrap; PipeWrap(Environment* env, v8::Local object, bool ipc, @@ -41,8 +36,6 @@ class PipeWrap : public StreamWrap { #endif static void AfterConnect(uv_connect_t* req, int status); - - uv_pipe_t handle_; }; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 78aaf1156625a1..873f19d26acf15 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -1,5 +1,6 @@ #include "tcp_wrap.h" +#include "connection_wrap.h" #include "env.h" #include "env-inl.h" #include "handle_wrap.h" @@ -8,7 +9,6 @@ #include "req-wrap.h" #include "req-wrap-inl.h" #include "stream_wrap.h" -#include "connection_wrap.h" #include "util.h" #include "util-inl.h" @@ -141,11 +141,10 @@ void TCPWrap::New(const FunctionCallbackInfo& args) { TCPWrap::TCPWrap(Environment* env, Local object, AsyncWrap* parent) - : StreamWrap(env, - object, - reinterpret_cast(&handle_), - AsyncWrap::PROVIDER_TCPWRAP, - parent) { + : ConnectionWrap(env, + object, + AsyncWrap::PROVIDER_TCPWRAP, + parent) { int r = uv_tcp_init(env->event_loop(), &handle_); CHECK_EQ(r, 0); // How do we proxy this error up to javascript? // Suggestion: uv_tcp_init() returns void. diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index d20a329e8d9ad6..26eb410c430a71 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -5,16 +5,12 @@ #include "async-wrap.h" #include "env.h" -#include "stream_wrap.h" #include "connection_wrap.h" namespace node { -class TCPWrap : public StreamWrap { +class TCPWrap : public ConnectionWrap { public: - uv_tcp_t* UVHandle() { - return &handle_; - } static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Local target, v8::Local unused, @@ -23,7 +19,6 @@ class TCPWrap : public StreamWrap { size_t self_size() const override { return sizeof(*this); } private: - friend class ConnectionWrap; typedef uv_tcp_t HandleType; template Date: Sun, 17 Jul 2016 05:55:20 +0200 Subject: [PATCH 20/23] Adding a destructor for ConnectionWrap --- src/connection_wrap.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 40842f224d327f..f1f848ddb16950 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -24,6 +24,8 @@ class ConnectionWrap : public StreamWrap { v8::Local object, ProviderType provider, AsyncWrap* parent); + ~ConnectionWrap() { + } UVType handle_; }; From 4feb84a768769b6527e1564d9ce0ccc90008dc0a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sun, 17 Jul 2016 06:02:23 +0200 Subject: [PATCH 21/23] Removing unnecessary template parameters for OnConnection --- src/pipe_wrap.cc | 2 +- src/tcp_wrap.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index cf14e49753227f..8baf04ba7cef6f 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -156,7 +156,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - ConnectionWrap::OnConnection); + OnConnection); args.GetReturnValue().Set(err); } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 873f19d26acf15..674c0592541b99 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -247,7 +247,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, - ConnectionWrap::OnConnection); + OnConnection); args.GetReturnValue().Set(err); } From 0a1ff38eba14cc77b3ed69c16564eab4bc6ad668 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sun, 17 Jul 2016 20:18:21 +0200 Subject: [PATCH 22/23] Removing the inclusion of async-wrap.h --- src/connection_wrap.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/connection_wrap.h b/src/connection_wrap.h index f1f848ddb16950..1702e22dd31188 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -3,7 +3,6 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "async-wrap.h" #include "env.h" #include "stream_wrap.h" #include "v8.h" From 85af1a609fc0562c321e08fdd20ab064104e972d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 20 Jul 2016 15:27:55 +0200 Subject: [PATCH 23/23] Removing the empty destructor in favour of an explicit default --- src/connection_wrap.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/connection_wrap.h b/src/connection_wrap.h index 1702e22dd31188..7f7a50ae7ca6cf 100644 --- a/src/connection_wrap.h +++ b/src/connection_wrap.h @@ -23,8 +23,7 @@ class ConnectionWrap : public StreamWrap { v8::Local object, ProviderType provider, AsyncWrap* parent); - ~ConnectionWrap() { - } + ~ConnectionWrap() = default; UVType handle_; };