-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: make send cb act as "error" event handler
Modifies the dgram send() method to not emit errors when a DNS lookup fails if there is a callback. Given that the same UDP socket can be used to send messages to different hosts, the socket can be reused even if one of those send() fails. This slightly changes the behavior of a stable API, so that it behaves as users would expect to. This is based on nodejs/node-v0.x-archive#7738, which landed in 77266d7. Fixes: nodejs/node-v0.x-archive#4846 Refs: nodejs/node-v0.x-archive#7738 PR-URL: #1796 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
- Loading branch information
Showing
4 changed files
with
41 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var mustCall = common.mustCall; | ||
var assert = require('assert'); | ||
var dgram = require('dgram'); | ||
var dns = require('dns'); | ||
|
||
var socket = dgram.createSocket('udp4'); | ||
var buffer = new Buffer('gary busey'); | ||
|
||
dns.setServers([]); | ||
|
||
socket.once('error', onEvent); | ||
|
||
// assert that: | ||
// * callbacks act as "error" listeners if given. | ||
// * error is never emitter for missing dns entries | ||
// if a callback that handles error is present | ||
// * error is emitted if a callback with no argument is passed | ||
socket.send(buffer, 0, buffer.length, 100, | ||
'dne.example.com', mustCall(callbackOnly)); | ||
|
||
function callbackOnly(err) { | ||
assert.ok(err); | ||
socket.removeListener('error', onEvent); | ||
socket.on('error', mustCall(onError)); | ||
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com'); | ||
} | ||
|
||
function onEvent(err) { | ||
assert.fail('Error should not be emitted if there is callback'); | ||
} | ||
|
||
function onError(err) { | ||
assert.ok(err); | ||
socket.close(); | ||
} |
This file was deleted.
Oops, something went wrong.