summaryrefslogtreecommitdiff
path: root/lib/dgram.js
diff options
context:
space:
mode:
authorOuyang Yadong <oyydoibh@gmail.com>2018-10-21 15:59:38 +0800
committerOuyang Yadong <oyydoibh@gmail.com>2018-11-22 21:45:08 +0800
commit33a25b29a4d654f5c2a5c74725862bccb2fcccfb (patch)
treea963b15bcba72cabfb317cbb00e47ff33753fbd9 /lib/dgram.js
parent91748dd89c652939d52f38b94afe9eae4eb8fd5d (diff)
downloadandroid-node-v8-33a25b29a4d654f5c2a5c74725862bccb2fcccfb.tar.gz
android-node-v8-33a25b29a4d654f5c2a5c74725862bccb2fcccfb.tar.bz2
android-node-v8-33a25b29a4d654f5c2a5c74725862bccb2fcccfb.zip
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 'lib/dgram.js')
-rw-r--r--lib/dgram.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/dgram.js b/lib/dgram.js
index 549b6dd738..55662313d6 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -54,7 +54,11 @@ const {
} = require('internal/async_hooks');
const { UV_UDP_REUSEADDR } = internalBinding('constants').os;
-const { UDP, SendWrap } = internalBinding('udp_wrap');
+const {
+ constants: { UV_UDP_IPV6ONLY },
+ UDP,
+ SendWrap
+} = internalBinding('udp_wrap');
const BIND_STATE_UNBOUND = 0;
const BIND_STATE_BINDING = 1;
@@ -99,6 +103,7 @@ function Socket(type, listener) {
bindState: BIND_STATE_UNBOUND,
queue: undefined,
reuseAddr: options && options.reuseAddr, // Use UV_UDP_REUSEADDR if true.
+ ipv6Only: options && options.ipv6Only,
recvBufferSize,
sendBufferSize
};
@@ -270,6 +275,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
var flags = 0;
if (state.reuseAddr)
flags |= UV_UDP_REUSEADDR;
+ if (state.ipv6Only)
+ flags |= UV_UDP_IPV6ONLY;
if (cluster.isWorker && !exclusive) {
bindServerHandle(this, {