| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7df4ee8 commit 874ef9d
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const dgram = require('dgram'); | ||
| 5 | + const UDP = process.binding('udp_wrap').UDP; | ||
| 6 | + const _createSocketHandle = dgram._createSocketHandle; | ||
| 7 | + | ||
| 8 | + // Throws if an "existing fd" is passed in. | ||
| 9 | + assert.throws(() => { | ||
| 10 | + _createSocketHandle(common.localhostIPv4, 0, 'udp4', 42); | ||
| 11 | + }, /^AssertionError: false == true$/); | ||
| 12 | + | ||
| 13 | + { | ||
| 14 | + // Create a handle that is not bound. | ||
| 15 | + const handle = _createSocketHandle(null, null, 'udp4'); | ||
| 16 | + | ||
| 17 | + assert(handle instanceof UDP); | ||
| 18 | + assert.strictEqual(typeof handle.fd, 'number'); | ||
| 19 | + assert(handle.fd < 0); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + { | ||
| 23 | + // Create a bound handle. | ||
| 24 | + const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4'); | ||
| 25 | + | ||
| 26 | + assert(handle instanceof UDP); | ||
| 27 | + assert.strictEqual(typeof handle.fd, 'number'); | ||
| 28 | + | ||
| 29 | + if (!common.isWindows) | ||
| 30 | + assert(handle.fd > 0); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + { | ||
| 34 | + // Return an error if binding fails. | ||
| 35 | + const err = _createSocketHandle('localhost', 0, 'udp4'); | ||
| 36 | + | ||
| 37 | + assert.strictEqual(typeof err, 'number'); | ||
| 38 | + assert(err < 0); | ||
| 39 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments