Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e3a4824
test: remove obsolete harmony flags
chrisdickinson May 5, 2015
b26a7cb
deps: update v8 to 4.3.61.21
chrisdickinson May 5, 2015
6950d62
doc: update v8 flags in man page
targos May 14, 2015
0925aba
Revert "dns: remove AI_V4MAPPED hint flag on FreeBSD"
cjihrig Apr 29, 2015
7a3e354
net: do not set V4MAPPED on FreeBSD
Mar 2, 2015
f49aed1
deps: backport 7b24219346 from v8 upstream
rvagg May 27, 2015
1ed4e13
buffer: allow ARGS_THIS to accept a name
trevnorris May 26, 2015
e8734c0
buffer: implement Uint8Array backed Buffer
trevnorris May 26, 2015
e435bf7
buffer: finish implementing FreeCallback
trevnorris Jun 1, 2015
ad91c1d
buffer: switch to using Maybe<T> API
trevnorris Jun 2, 2015
2903030
buffer: switch API to return MaybeLocal<T>
trevnorris Jun 2, 2015
07924b8
buffer: make additional changes to native API
trevnorris Jun 2, 2015
53f8549
crypto: remove kMaxLength on randomBytes()
trevnorris Jun 2, 2015
84c58a3
vm: fix property descriptors of sandbox properties
domenic May 22, 2015
9093ea7
vm: remove unnecessary access checks
domenic May 23, 2015
84950bc
vm: fix symbol access
domenic Jun 1, 2015
1da8ec3
dgram: make send cb act as "error" event handler
chrisdickinson Jun 5, 2014
59a23ed
dgram: make send cb act as "error" event handler
mcollina May 26, 2015
646d67b
http_server: `prefinish` vs `finish`
indutny Apr 13, 2015
a799038
buffer: fix case of one buffer passed to concat
thefourtheye Jun 10, 2015
309c0f4
cluster: do not unconditionally set --debug-port
cjihrig Jun 11, 2015
74772b4
buffer: fix usage of kMaxLength
trevnorris Jun 17, 2015
f115dfc
buffer: minor cleanup from rebase
trevnorris Jun 17, 2015
197ba00
buffer: allow ArrayBuffer as Buffer argument
trevnorris Jun 17, 2015
90c72d4
readline: allow tabs in input
Trott May 21, 2015
4527bbf
deps: update v8 to 4.4.63.9
bnoordhuis Jun 19, 2015
67d9391
test: don't use arguments.callee
bnoordhuis Jun 19, 2015
8835c3d
test: remove two obsolete pummel tests
bnoordhuis Jun 19, 2015
d15ddea
buffer: rename internal/buffer_new.js to buffer.js
bnoordhuis Jun 19, 2015
6e72ac7
Merge tag 'v2.3.1' into next
bnoordhuis Jun 25, 2015
033a728
build,win: set env before generating projects
orangemocha Apr 23, 2015
0fb8d45
build: add MSVS 2015 support
rvagg Apr 16, 2015
32c6a66
build: fix cherry-pick ooops, fix comment wording
rvagg Jun 23, 2015
c4bba16
build: update build targets for io.js
rvagg Jun 10, 2015
a6bc75d
build: add tar-headers target for headers-only tar
rvagg Jun 14, 2015
bda3a2d
node-gyp: make aware of nightly, next-nightly & rc
rvagg Jun 26, 2015
8f6f428
node-gyp: download header tarball for compile
rvagg Jun 26, 2015
483aac9
Working on v3.0.0
rvagg Jun 30, 2015
bf7df17
deps: upgrade v8 to 4.4.63.12
bnoordhuis Jul 1, 2015
a5745aa
src: increment NODE_MODULE_VERSION to 45
rvagg Jul 2, 2015
8a1986f
src: update comment for NODE_MODULE_VERSION
rvagg Jul 2, 2015
7387297
test: add test for missing `close`/`finish` event
not-implemented Apr 13, 2015
3beae2c
Merge branch 'master' into next
trevnorris Jul 10, 2015
cbec3ee
node: do not override `message`/`stack` of error
indutny Jul 5, 2015
235036e
http: use official IANA Status Codes
jomo Jul 11, 2015
cf9e02d
buffer: fix not return on error
trevnorris Jul 22, 2015
4737dcd
build: first set of updates to enable PPC support
mhdawson Jul 7, 2015
9cf36a1
buffer: fix missing null/undefined check
trevnorris Jul 16, 2015
115bf08
node: remove redundant --use-old-buffer
rvagg Jul 30, 2015
f0de101
http: fix agent.getName() and add tests
brendanashworth May 5, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dgram: make send cb act as "error" event handler
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
chrisdickinson committed Jun 17, 2015
commit 1da8ec35fcdfe0fcca95a5be5b853eb4ce4677d3
4 changes: 3 additions & 1 deletion doc/api/dgram.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ assigned a random port number and is bound to the "all interfaces" address
An optional callback may be specified to detect DNS errors or for determining
when it's safe to reuse the `buf` object. Note that DNS lookups delay the time
to send for at least one tick. The only way to know for sure that the datagram
has been sent is by using a callback.
has been sent is by using a callback. If an error occurs and a callback is given,
the error will be the first argument to the callback. If a callback is not given,
the error is emitted as an `'error'` event on the `socket` object.

With consideration for multi-byte characters, `offset` and `length` will
be calculated with respect to
Expand Down
10 changes: 9 additions & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,15 @@ Socket.prototype.send = function(buffer,

self._handle.lookup(address, function(ex, ip) {
if (ex) {
if (callback) callback(ex);
if (callback) {
callback(ex);

if (self.listeners('error').length)
self.emit('error', ex);

return;
}

self.emit('error', ex);
} else if (self._handle) {
var req = new SendWrap();
Expand Down
54 changes: 54 additions & 0 deletions test/simple/test-dgram-send-cb-quelches-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var dgram = require('dgram');
var dns = require('dns');

var socket = dgram.createSocket('udp4');
var buffer = new Buffer('gary busey');
var times = 0;

dns.setServers([]);

// assert that:
// * callbacks act as "error" listeners if given.
// * callbacks and error events are emitted in a certain order.
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com', callbackOnly);

function callbackOnly(err) {
assert.ok(err);
socket.once('error', onEvent);
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com', onCallback);
}

function onEvent(err) {
assert.ok(err);
assert.equal(times, 0);
times++;
}

function onCallback(err) {
assert.ok(err);
assert.equal(times, 1);
socket.close();
}