diff options
author | Chris Dickinson <christopher.s.dickinson@gmail.com> | 2014-06-05 12:42:41 -0700 |
---|---|---|
committer | Rod Vagg <rod@vagg.org> | 2015-08-04 11:56:12 -0700 |
commit | 3da057fef672da0d1f0173a2c8b4f64737917e19 (patch) | |
tree | eddbcf0bbba8841897e8894116c6df985e8c5d17 /lib | |
parent | 3b021efe11ea6828ed8c856167fc6f5e20b18fcc (diff) | |
download | android-node-v8-3da057fef672da0d1f0173a2c8b4f64737917e19.tar.gz android-node-v8-3da057fef672da0d1f0173a2c8b4f64737917e19.tar.bz2 android-node-v8-3da057fef672da0d1f0173a2c8b4f64737917e19.zip |
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: https://github.com/joyent/node/issues/4846
PR-URL: https://github.com/joyent/node/pull/7738
PR-URL: https://github.com/nodejs/io.js/pull/1796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dgram.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/dgram.js b/lib/dgram.js index 22dc7a2319..8cf5d30779 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -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(); |