Skip to content

Commit 620a98d

Browse files
committed
net: use common internal method
1 parent 843698c commit 620a98d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/tcp_wrap.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
178178

179179
TCPWrap::TCPWrap(Environment* env, Local<Object> object, ProviderType provider)
180180
: ConnectionWrap(env, object, provider) {
181-
int r = uv_tcp_init(env->event_loop(), &handle_);
182-
CHECK_EQ(r, 0); // How do we proxy this error up to javascript?
183-
// Suggestion: uv_tcp_init() returns void.
181+
this->InitializeHandle();
184182
}
185183

186184
void TCPWrap::Reinitialize(const FunctionCallbackInfo<Value>& args) {
@@ -189,9 +187,7 @@ void TCPWrap::Reinitialize(const FunctionCallbackInfo<Value>& args) {
189187
ASSIGN_OR_RETURN_UNWRAP(
190188
&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF));
191189

192-
Environment* env = wrap->env();
193-
int r = uv_tcp_init(env->event_loop(), &wrap->handle_);
194-
CHECK_EQ(r, 0);
190+
wrap->InitializeHandle();
195191
}
196192

197193
void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
@@ -394,6 +390,13 @@ int TCPWrap::Reset(Local<Value> close_callback) {
394390
return err;
395391
}
396392

393+
void TCPWrap::InitializeHandle() {
394+
int r = uv_tcp_init(this->env()->event_loop(), &handle_);
395+
396+
CHECK_EQ(r, 0); // How do we proxy this error up to javascript?
397+
// Suggestion: uv_tcp_init() returns void.
398+
}
399+
397400
// also used by udp_wrap.cc
398401
MaybeLocal<Object> AddressToJS(Environment* env,
399402
const sockaddr* addr,

src/tcp_wrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
9191
std::function<int(const char* ip_address, int port, T* addr)> uv_ip_addr);
9292
static void Reset(const v8::FunctionCallbackInfo<v8::Value>& args);
9393
int Reset(v8::Local<v8::Value> close_callback = v8::Local<v8::Value>());
94+
void InitializeHandle();
9495

9596
#ifdef _WIN32
9697
static void SetSimultaneousAccepts(

0 commit comments

Comments
 (0)