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>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
const common = require('../common');
|
|
if (common.isWindows)
|
|
common.skip('Does not support binding fd on Windows');
|
|
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
const { UDP } = internalBinding('udp_wrap');
|
|
const { TCP, constants } = internalBinding('tcp_wrap');
|
|
const _createSocketHandle = dgram._createSocketHandle;
|
|
|
|
// Return a negative number if the "existing fd" is invalid.
|
|
{
|
|
const err = _createSocketHandle(common.localhostIPv4, 0, 'udp4', 42);
|
|
assert(err < 0);
|
|
}
|
|
|
|
// Return a negative number if the type of fd is not "UDP".
|
|
{
|
|
// Create a handle with fd.
|
|
const rawHandle = new UDP();
|
|
const err = rawHandle.bind(common.localhostIPv4, 0, 0);
|
|
assert(err >= 0, String(err));
|
|
assert.notStrictEqual(rawHandle.fd, -1);
|
|
|
|
const handle = _createSocketHandle(null, 0, 'udp4', rawHandle.fd);
|
|
assert(handle instanceof UDP);
|
|
assert.strictEqual(typeof handle.fd, 'number');
|
|
assert(handle.fd > 0);
|
|
}
|
|
|
|
// Create a bound handle.
|
|
{
|
|
const rawHandle = new TCP(constants.SOCKET);
|
|
const err = rawHandle.listen();
|
|
assert(err >= 0, String(err));
|
|
assert.notStrictEqual(rawHandle.fd, -1);
|
|
|
|
const handle = _createSocketHandle(null, 0, 'udp4', rawHandle.fd);
|
|
assert(handle < 0);
|
|
rawHandle.close();
|
|
}
|