mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: improve error handling in tcp_wrap.cc
PR-URL: https://github.com/nodejs/node/pull/57211 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
d7d54e6bf3
commit
567d321a40
1 file changed
+32
-18
+32
-18
@@ -390,8 +390,9 @@ MaybeLocal<Object> AddressToJS(Environment* env,
|
||||
|
||||
int port;
|
||||
|
||||
if (info.IsEmpty())
|
||||
if (info.IsEmpty()) {
|
||||
info = Object::New(env->isolate());
|
||||
}
|
||||
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET6:
|
||||
@@ -413,32 +414,45 @@ MaybeLocal<Object> AddressToJS(Environment* env,
|
||||
}
|
||||
}
|
||||
port = ntohs(a6->sin6_port);
|
||||
info->Set(env->context(),
|
||||
env->address_string(),
|
||||
OneByteString(env->isolate(), ip)).Check();
|
||||
info->Set(env->context(), env->family_string(), env->ipv6_string()).Check();
|
||||
info->Set(env->context(),
|
||||
env->port_string(),
|
||||
Integer::New(env->isolate(), port)).Check();
|
||||
if (info->Set(env->context(),
|
||||
env->address_string(),
|
||||
OneByteString(env->isolate(), ip))
|
||||
.IsNothing() ||
|
||||
info->Set(env->context(), env->family_string(), env->ipv6_string())
|
||||
.IsNothing() ||
|
||||
info->Set(env->context(),
|
||||
env->port_string(),
|
||||
Integer::New(env->isolate(), port))
|
||||
.IsNothing()) {
|
||||
return {};
|
||||
}
|
||||
break;
|
||||
|
||||
case AF_INET:
|
||||
a4 = reinterpret_cast<const sockaddr_in*>(addr);
|
||||
uv_inet_ntop(AF_INET, &a4->sin_addr, ip, sizeof ip);
|
||||
port = ntohs(a4->sin_port);
|
||||
info->Set(env->context(),
|
||||
env->address_string(),
|
||||
OneByteString(env->isolate(), ip)).Check();
|
||||
info->Set(env->context(), env->family_string(), env->ipv4_string()).Check();
|
||||
info->Set(env->context(),
|
||||
env->port_string(),
|
||||
Integer::New(env->isolate(), port)).Check();
|
||||
if (info->Set(env->context(),
|
||||
env->address_string(),
|
||||
OneByteString(env->isolate(), ip))
|
||||
.IsNothing() ||
|
||||
info->Set(env->context(), env->family_string(), env->ipv4_string())
|
||||
.IsNothing() ||
|
||||
info->Set(env->context(),
|
||||
env->port_string(),
|
||||
Integer::New(env->isolate(), port))
|
||||
.IsNothing()) {
|
||||
return {};
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
info->Set(env->context(),
|
||||
env->address_string(),
|
||||
String::Empty(env->isolate())).Check();
|
||||
if (info->Set(env->context(),
|
||||
env->address_string(),
|
||||
String::Empty(env->isolate()))
|
||||
.IsNothing()) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return scope.Escape(info);
|
||||
|
||||
Reference in new issue
Block a user