diff options
author | Christopher Hiller <boneskull@boneskull.com> | 2017-01-12 22:10:26 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-02-17 13:12:51 -0800 |
commit | 32679c73c11c618d027095d96b00f2a77b243d4d (patch) | |
tree | da48250a893b0e436893f2594dbbcf44a2356811 /test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js | |
parent | b514bd231ed8926a0037b78e85d267a602c2e7cd (diff) | |
download | android-node-v8-32679c73c11c618d027095d96b00f2a77b243d4d.tar.gz android-node-v8-32679c73c11c618d027095d96b00f2a77b243d4d.tar.bz2 android-node-v8-32679c73c11c618d027095d96b00f2a77b243d4d.zip |
dgram: improve signature of Socket.prototype.send
- Do not require presence of `address` parameter to use `callback`
parameter; `address` is *always* optional
- Improve exception messaging if `address` is invalid type
- If `address` is an invalid type, guarantee a synchronously thrown
exception
- Update documentation to reflect signature changes
- Add coverage around valid, undocumented types for `address` parameter.
- Add coverage around known invalid, but uncovered, types for `address`
parameter.
PR-URL: https://github.com/nodejs/node/pull/10473
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js')
-rw-r--r-- | test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js b/test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js new file mode 100644 index 0000000000..cef71083c7 --- /dev/null +++ b/test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js @@ -0,0 +1,28 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const dgram = require('dgram'); + +const client = dgram.createSocket('udp4'); + +const messageSent = common.mustCall(function messageSent(err, bytes) { + assert.ifError(err); + assert.strictEqual(bytes, buf1.length + buf2.length); +}); + +const buf1 = Buffer.alloc(256, 'x'); +const buf2 = Buffer.alloc(256, 'y'); + +client.on('listening', function() { + const port = this.address().port; + client.send([buf1, buf2], port, messageSent); +}); + +client.on('message', common.mustCall(function onMessage(buf) { + const expected = Buffer.concat([buf1, buf2]); + assert.ok(buf.equals(expected), 'message was received correctly'); + client.close(); +})); + +client.bind(0); |