diff options
author | Evan Lucas <evanlucas@me.com> | 2015-04-22 17:05:29 -0500 |
---|---|---|
committer | Evan Lucas <evanlucas@me.com> | 2015-04-24 07:53:16 -0500 |
commit | 4abe2fa1cfcc434952570c1c979dd4ce150fba67 (patch) | |
tree | 38ff3f63ca1e507928d85c6f1be296f363a46b05 /test | |
parent | 1bef71747678c19c7214048de5b9e3848889248d (diff) | |
download | android-node-v8-4abe2fa1cfcc434952570c1c979dd4ce150fba67.tar.gz android-node-v8-4abe2fa1cfcc434952570c1c979dd4ce150fba67.tar.bz2 android-node-v8-4abe2fa1cfcc434952570c1c979dd4ce150fba67.zip |
net: add lookup option to Socket.prototype.connect
Allows customization of the lookup function used when
Socket.prototype.connect is called using a hostname.
PR-URL: https://github.com/iojs/io.js/pull/1505
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-net-dns-custom-lookup.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-net-dns-custom-lookup.js b/test/parallel/test-net-dns-custom-lookup.js new file mode 100644 index 0000000000..3979bbf0b6 --- /dev/null +++ b/test/parallel/test-net-dns-custom-lookup.js @@ -0,0 +1,40 @@ +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); +var dns = require('dns'); +var ok = false; + +function check(addressType, cb) { + var server = net.createServer(function(client) { + client.end(); + server.close(); + cb && cb(); + }); + + var address = addressType === 4 ? '127.0.0.1' : '::1'; + server.listen(common.PORT, address, function() { + net.connect({ + port: common.PORT, + host: 'localhost', + lookup: lookup + }).on('lookup', function(err, ip, type) { + assert.equal(err, null); + assert.equal(ip, address); + assert.equal(type, addressType); + ok = true; + }); + }); + + function lookup(host, dnsopts, cb) { + dnsopts.family = addressType; + dns.lookup(host, dnsopts, cb); + } +} + +check(4, function() { + common.hasIPv6 && check(6); +}); + +process.on('exit', function() { + assert.ok(ok); +}); |