mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c8950cdabc
PR-URL: https://github.com/nodejs/node/pull/22475 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
36 lines
900 B
JavaScript
36 lines
900 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { _createSocketHandle } = require('internal/dgram');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
const UDP = internalBinding('udp_wrap').UDP;
|
|
|
|
{
|
|
// Create a handle that is not bound.
|
|
const handle = _createSocketHandle(null, null, 'udp4');
|
|
|
|
assert(handle instanceof UDP);
|
|
assert.strictEqual(typeof handle.fd, 'number');
|
|
assert(handle.fd < 0);
|
|
}
|
|
|
|
{
|
|
// Create a bound handle.
|
|
const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4');
|
|
|
|
assert(handle instanceof UDP);
|
|
assert.strictEqual(typeof handle.fd, 'number');
|
|
|
|
if (!common.isWindows)
|
|
assert(handle.fd > 0);
|
|
}
|
|
|
|
{
|
|
// Return an error if binding fails.
|
|
const err = _createSocketHandle('localhost', 0, 'udp4');
|
|
|
|
assert.strictEqual(typeof err, 'number');
|
|
assert(err < 0);
|
|
}
|