| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3185fa1 commit 7596049
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,36 +4,22 @@ const common = require('../common'); | |||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const dgram = require('dgram'); | |
| 6 | 6 | ||
| 7 | - const setup = () => { | ||
| 8 | - return dgram.createSocket({type: 'udp4', reuseAddr: true}); | ||
| 9 | - }; | ||
| 7 | + { | ||
| 8 | + // Should throw EBADF if the socket is never bound. | ||
| 9 | + const socket = dgram.createSocket('udp4'); | ||
| 10 | 10 | ||
| 11 | - const teardown = (socket) => { | ||
| 12 | - if (socket.close) | ||
| 13 | - socket.close(); | ||
| 14 | - }; | ||
| 15 | - | ||
| 16 | - const runTest = (testCode, expectError) => { | ||
| 17 | - const socket = setup(); | ||
| 18 | - const assertion = expectError ? assert.throws : assert.doesNotThrow; | ||
| 19 | - const wrapped = () => { testCode(socket); }; | ||
| 20 | - assertion(wrapped, expectError); | ||
| 21 | - teardown(socket); | ||
| 22 | - }; | ||
| 11 | + assert.throws(() => { | ||
| 12 | + socket.setBroadcast(true); | ||
| 13 | + }, /^Error: setBroadcast EBADF$/); | ||
| 14 | + } | ||
| 23 | 15 | ||
| 24 | - // Should throw EBADF if socket is never bound. | ||
| 25 | - runTest((socket) => { socket.setBroadcast(true); }, /EBADF/); | ||
| 16 | + { | ||
| 17 | + // Can call setBroadcast() after binding the socket. | ||
| 18 | + const socket = dgram.createSocket('udp4'); | ||
| 26 | 19 | ||
| 27 | - // Should not throw if broadcast set to false after binding. | ||
| 28 | - runTest((socket) => { | ||
| 29 | - socket.bind(0, common.localhostIPv4, () => { | ||
| 30 | - socket.setBroadcast(false); | ||
| 31 | - }); | ||
| 32 | - }); | ||
| 33 | - | ||
| 34 | - // Should not throw if broadcast set to true after binding. | ||
| 35 | - runTest((socket) => { | ||
| 36 | - socket.bind(0, common.localhostIPv4, () => { | ||
| 20 | + socket.bind(0, common.mustCall(() => { | ||
| 37 | 21 | socket.setBroadcast(true); | |
| 38 | - }); | ||
| 39 | - }); | ||
| 22 | + socket.setBroadcast(false); | ||
| 23 | + socket.close(); | ||
| 24 | + })); | ||
| 25 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments