node/test/parallel/test-dgram-send-callback-buffer.js
cjihrig 4bc1cccb22 dgram: pass null as error on successful send()
Prior to c9fd9e2162, UDP sockets
would callback with a null error on successful send() calls. The
current behavior is to pass 0 as the error. This commit restores
the previous, more expected behavior.

PR-URL: https://github.com/nodejs/node/pull/5929
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-28 09:47:13 -04:00

23 lines
538 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustCall(function(err, bytes) {
assert.strictEqual(err, null);
assert.equal(bytes, buf.length);
clearTimeout(timer);
client.close();
});
const timer = setTimeout(function() {
throw new Error('Timeout');
}, common.platformTimeout(200));
client.send(buf, common.PORT, common.localhostIPv4, onMessage);