mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
984 B
39 lines
984 B
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
|
|
const setup = () => {
|
|
return dgram.createSocket({type: 'udp4', reuseAddr: true});
|
|
};
|
|
|
|
const teardown = (socket) => {
|
|
if (socket.close)
|
|
socket.close();
|
|
};
|
|
|
|
const runTest = (testCode, expectError) => {
|
|
const socket = setup();
|
|
const assertion = expectError ? assert.throws : assert.doesNotThrow;
|
|
const wrapped = () => { testCode(socket); };
|
|
assertion(wrapped, expectError);
|
|
teardown(socket);
|
|
};
|
|
|
|
// Should throw EBADF if socket is never bound.
|
|
runTest((socket) => { socket.setBroadcast(true); }, /EBADF/);
|
|
|
|
// Should not throw if broadcast set to false after binding.
|
|
runTest((socket) => {
|
|
socket.bind(0, common.localhostIPv4, () => {
|
|
socket.setBroadcast(false);
|
|
});
|
|
});
|
|
|
|
// Should not throw if broadcast set to true after binding.
|
|
runTest((socket) => {
|
|
socket.bind(0, common.localhostIPv4, () => {
|
|
socket.setBroadcast(true);
|
|
});
|
|
});
|
|
|