aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-bind-fd-error.js
diff options
context:
space:
mode:
authorOuyang Yadong <oyydoibh@gmail.com>2018-07-29 22:41:11 +0800
committerMatteo Collina <hello@matteocollina.com>2018-08-06 11:05:51 +0200
commit2bea9cefbc10ed1dd497bbae61c07d971da287dd (patch)
tree02bfcbc3fcf39fe7524f9271762617f23e107925 /test/parallel/test-dgram-bind-fd-error.js
parent214844ea4e561b0f77e97643d28b251cdc574089 (diff)
downloadandroid-node-v8-2bea9cefbc10ed1dd497bbae61c07d971da287dd.tar.gz
android-node-v8-2bea9cefbc10ed1dd497bbae61c07d971da287dd.tar.bz2
android-node-v8-2bea9cefbc10ed1dd497bbae61c07d971da287dd.zip
dgram: implement socket.bind({ fd })
dgram: Implement binding an existing `fd`. Allow pass a `fd` property to `socket.bind()` in dgram. src: Add `UDPWrap::Open` PR-URL: https://github.com/nodejs/node/pull/21745 Fixes: https://github.com/nodejs/node/issues/14961 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-dgram-bind-fd-error.js')
-rw-r--r--test/parallel/test-dgram-bind-fd-error.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-bind-fd-error.js b/test/parallel/test-dgram-bind-fd-error.js
new file mode 100644
index 0000000000..efe0e43d7b
--- /dev/null
+++ b/test/parallel/test-dgram-bind-fd-error.js
@@ -0,0 +1,55 @@
+// 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 { TCP, constants } = process.binding('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();
+}