summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/dgram.js21
-rw-r--r--test/parallel/test-dgram-send-bad-arguments.js9
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/dgram.js b/lib/dgram.js
index cb20c4499a..e032a6f7fd 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -561,16 +561,19 @@ Socket.prototype.send = function(buffer,
port = offset;
address = length;
}
- } else if (typeof length === 'number') {
- buffer = sliceBuffer(buffer, offset, length);
- if (typeof port === 'function') {
- callback = port;
- port = null;
- } else if (port || address) {
- throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
- }
} else {
- callback = offset;
+ if (typeof length === 'number') {
+ buffer = sliceBuffer(buffer, offset, length);
+ if (typeof port === 'function') {
+ callback = port;
+ port = null;
+ }
+ } else {
+ callback = offset;
+ }
+
+ if (port || address)
+ throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
}
if (!Array.isArray(buffer)) {
diff --git a/test/parallel/test-dgram-send-bad-arguments.js b/test/parallel/test-dgram-send-bad-arguments.js
index 467efbb7b9..f8f2a2de13 100644
--- a/test/parallel/test-dgram-send-bad-arguments.js
+++ b/test/parallel/test-dgram-send-bad-arguments.js
@@ -68,6 +68,15 @@ function checkArgs(connected) {
message: 'Already connected'
}
);
+
+ common.expectsError(
+ () => { sock.send(buf, 1234, '127.0.0.1', common.mustNotCall()); },
+ {
+ code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
+ type: Error,
+ message: 'Already connected'
+ }
+ );
} else {
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);