src: unifying PipeConnectWrap and TCPConnectWrap · nodejs/node@b896057
@@ -6,8 +6,7 @@
66#include "handle_wrap.h"
77#include "node_buffer.h"
88#include "node_wrap.h"
9-#include "req-wrap.h"
10-#include "req-wrap-inl.h"
9+#include "connect_wrap.h"
1110#include "stream_wrap.h"
1211#include "util.h"
1312#include "util-inl.h"
@@ -32,24 +31,6 @@ using v8::String;
3231using v8::Value;
3332343335-class TCPConnectWrap : public ReqWrap<uv_connect_t> {
36-public:
37-TCPConnectWrap(Environment* env, Local<Object> req_wrap_obj);
38-size_t self_size() const override { return sizeof(*this); }
39-};
40-41-42-TCPConnectWrap::TCPConnectWrap(Environment* env, Local<Object> req_wrap_obj)
43- : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP) {
44-Wrap(req_wrap_obj, this);
45-}
46-47-48-static void NewTCPConnectWrap(const FunctionCallbackInfo<Value>& args) {
49-CHECK(args.IsConstructCall());
50-}
51-52-5334Local<Object> TCPWrap::Instantiate(Environment* env, AsyncWrap* parent) {
5435 EscapableHandleScope handle_scope(env->isolate());
5536CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
@@ -112,8 +93,10 @@ void TCPWrap::Initialize(Local<Object> target,
11293 env->set_tcp_constructor_template(t);
1139411495// Create FunctionTemplate for TCPConnectWrap.
115- Local<FunctionTemplate> cwt =
116-FunctionTemplate::New(env->isolate(), NewTCPConnectWrap);
96+auto constructor = [](const FunctionCallbackInfo<Value>& args) {
97+CHECK(args.IsConstructCall());
98+ };
99+auto cwt = FunctionTemplate::New(env->isolate(), constructor);
117100 cwt->InstanceTemplate()->SetInternalFieldCount(1);
118101 cwt->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap"));
119102 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap"),
@@ -253,7 +236,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
253236254237255238void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
256-TCPConnectWrap* req_wrap = static_cast<TCPConnectWrap*>(req->data);
239+ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data);
257240 TCPWrap* wrap = static_cast<TCPWrap*>(req->handle->data);
258241CHECK_EQ(req_wrap->env(), wrap->env());
259242 Environment* env = wrap->env();
@@ -300,7 +283,8 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
300283int err = uv_ip4_addr(*ip_address, port, &addr);
301284302285if (err == 0) {
303- TCPConnectWrap* req_wrap = new TCPConnectWrap(env, req_wrap_obj);
286+ ConnectWrap* req_wrap =
287+new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP);
304288 err = uv_tcp_connect(&req_wrap->req_,
305289&wrap->handle_,
306290reinterpret_cast<const sockaddr*>(&addr),
@@ -334,7 +318,8 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
334318int err = uv_ip6_addr(*ip_address, port, &addr);
335319336320if (err == 0) {
337- TCPConnectWrap* req_wrap = new TCPConnectWrap(env, req_wrap_obj);
321+ ConnectWrap* req_wrap =
322+new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP);
338323 err = uv_tcp_connect(&req_wrap->req_,
339324&wrap->handle_,
340325reinterpret_cast<const sockaddr*>(&addr),