node/test/parallel/test-dgram-bind-fd-error.js
Daniel Bevenius 57d98bc732 src: move process.binding('tcp_wrap') to internal
This commit makes the tcp_wrap builtin an internal builtin, and
changes usage of the builtin from using process.binding('tcp_wrap')
to use internalBinding instead.

Refs: https://github.com/nodejs/node/issues/22160

PR-URL: https://github.com/nodejs/node/pull/22432
Refs: https://github.com/nodejs/node/issues/22160
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-08-24 09:10:38 +02:00

57 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 dgram = require('dgram');
const assert = require('assert');
const { kStateSymbol } = require('internal/dgram');
const { internalBinding } = require('internal/test/binding');
const { TCP, constants } = internalBinding('tcp_wrap');
const TYPE = 'udp4';
// Throw when the fd is occupied according to https://github.com/libuv/libuv/pull/1851.
{
const socket = dgram.createSocket(TYPE);
socket.bind(common.mustCall(() => {
const anotherSocket = dgram.createSocket(TYPE);
const { handle } = socket[kStateSymbol];
common.expectsError(() => {
anotherSocket.bind({
fd: handle.fd,
});
}, {
code: 'EEXIST',
type: Error,
message: /^open EEXIST$/
});
socket.close();
}));
}
// Throw when the type of fd is not "UDP".
{
const handle = new TCP(constants.SOCKET);
handle.listen();
const fd = handle.fd;
assert.notStrictEqual(fd, -1);
const socket = new dgram.createSocket(TYPE);
common.expectsError(() => {
socket.bind({
fd,
});
}, {
code: 'ERR_INVALID_FD_TYPE',
type: TypeError,
message: /^Unsupported fd type: TCP$/
});
handle.close();
}