From 5a050550d377c53a9249f218888ea2e92a4d48dc Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 31 Jul 2017 20:38:06 -0400 Subject: [PATCH] dgram: add custom lookup function in sockets This commit adds support for custom DNS lookup functions in dgram sockets. This is similar to the existing feature in net sockets. Refs: https://github.com/nodejs/node/issues/6189 PR-URL: https://github.com/nodejs/node/pull/14560 Reviewed-By: James M Snell Reviewed-By: Wyatt Preul Reviewed-By: Evan Lucas --- doc/api/dgram.md | 38 ++++++++++-------- lib/dgram.js | 32 ++++++++------- test/parallel/test-dgram-custom-lookup.js | 47 +++++++++++++++++++++++ 3 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 test/parallel/test-dgram-custom-lookup.js diff --git a/doc/api/dgram.md b/doc/api/dgram.md index 22fb2b5bbf..c3fcfb0528 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -455,27 +455,30 @@ s.bind(1234, () => { ### dgram.createSocket(options[, callback]) -* `options` {Object} -* `callback` {Function} Attached as a listener to `'message'` events. +* `options` {Object} Available options are: + * `type` {string} The family of socket. Must be either `'udp4'` or `'udp6'`. + Required. + * `reuseAddr` {boolean} When `true` [`socket.bind()`][] will reuse the + address, even if another process has already bound a socket on it. Optional. + Defaults to `false`. + * `lookup` {Function} Custom lookup function. Defaults to [`dns.lookup()`][]. + Optional. +* `callback` {Function} Attached as a listener for `'message'` events. Optional. * Returns: {dgram.Socket} -Creates a `dgram.Socket` object. The `options` argument is an object that -should contain a `type` field of either `udp4` or `udp6` and an optional -boolean `reuseAddr` field. - -When `reuseAddr` is `true` [`socket.bind()`][] will reuse the address, even if -another process has already bound a socket on it. `reuseAddr` defaults to -`false`. The optional `callback` function is added as a listener for `'message'` -events. - -Once the socket is created, calling [`socket.bind()`][] will instruct the -socket to begin listening for datagram messages. When `address` and `port` are -not passed to [`socket.bind()`][] the method will bind the socket to the "all -interfaces" address on a random port (it does the right thing for both `udp4` -and `udp6` sockets). The bound address and port can be retrieved using -[`socket.address().address`][] and [`socket.address().port`][]. +Creates a `dgram.Socket` object. Once the socket is created, calling +[`socket.bind()`][] will instruct the socket to begin listening for datagram +messages. When `address` and `port` are not passed to [`socket.bind()`][] the +method will bind the socket to the "all interfaces" address on a random port +(it does the right thing for both `udp4` and `udp6` sockets). The bound address +and port can be retrieved using [`socket.address().address`][] and +[`socket.address().port`][]. ### dgram.createSocket(type[, callback])