diff options
author | Ouyang Yadong <oyydoibh@gmail.com> | 2018-10-21 10:59:38 +0300 |
---|---|---|
committer | Ouyang Yadong <oyydoibh@gmail.com> | 2018-11-22 16:45:08 +0300 |
commit | 33a25b29a4d654f5c2a5c74725862bccb2fcccfb (patch) | |
tree | a963b15bcba72cabfb317cbb00e47ff33753fbd9 /src/tcp_wrap.cc | |
parent | 91748dd89c652939d52f38b94afe9eae4eb8fd5d (diff) |
net,dgram: add ipv6Only option for net and dgram
For TCP servers, the dual-stack support is enable by default, i.e.
binding host "::" will also make "0.0.0.0" bound. This commit add
ipv6Only option in `net.Server.listen()` and `dgram.createSocket()`
methods which allows to disable dual-stack support. Support for
cluster module is also provided in this commit.
Fixes: https://github.com/nodejs/node/issues/17664
PR-URL: https://github.com/nodejs/node/pull/23798
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/tcp_wrap.cc')
-rw-r--r-- | src/tcp_wrap.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index e1316b42cd2..504fda3de6c 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -127,6 +127,7 @@ void TCPWrap::Initialize(Local<Object> target, Local<Object> constants = Object::New(env->isolate()); NODE_DEFINE_CONSTANT(constants, SOCKET); NODE_DEFINE_CONSTANT(constants, SERVER); + NODE_DEFINE_CONSTANT(constants, UV_TCP_IPV6ONLY); target->Set(context, env->constants_string(), constants).FromJust(); @@ -252,13 +253,15 @@ void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) { Environment* env = wrap->env(); node::Utf8Value ip6_address(env->isolate(), args[0]); int port; + unsigned int flags; if (!args[1]->Int32Value(env->context()).To(&port)) return; + if (!args[2]->Uint32Value(env->context()).To(&flags)) return; sockaddr_in6 addr; int err = uv_ip6_addr(*ip6_address, port, &addr); if (err == 0) { err = uv_tcp_bind(&wrap->handle_, reinterpret_cast<const sockaddr*>(&addr), - 0); + flags); } args.GetReturnValue().Set(err); } |