Skip to content

Commit

Permalink
src: use UV_EINVAL instead of EINVAL in udp_wrap
Browse files Browse the repository at this point in the history
Currently if the buffer size exceeds the maximum int size the following
error will be thrown:
dgram.js:180
    throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e);
    ^

Error [ERR_SOCKET_BUFFER_SIZE]: Could not get or set buffer size: Error:
Unknown system error 22: Unknown system error 22, uv_recv_buffer_size
    at bufferSize (dgram.js:180:11)

It looks like perhaps UV_EINVAL was intended to give the following error
message instead:
dgram.js:180
    throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e);
    ^

Error [ERR_SOCKET_BUFFER_SIZE]: Could not get or set buffer size: Error:
EINVAL: invalid argument, uv_recv_buffer_size
    at bufferSize (dgram.js:180:11)

This commit changes EINVAL to use UV_EINVAL.

PR-URL: #15444
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
danbev committed Sep 22, 2017
1 parent 3888a57 commit f4899ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {

if (!args[0]->IsInt32()) {
if (args[1].As<Uint32>()->Value() == 0)
return env->ThrowUVException(EINVAL, "uv_recv_buffer_size");
return env->ThrowUVException(UV_EINVAL, "uv_recv_buffer_size");
else
return env->ThrowUVException(EINVAL, "uv_send_buffer_size");
return env->ThrowUVException(UV_EINVAL, "uv_send_buffer_size");
}

int err;
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-dgram-socket-buffer-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,24 @@ const dgram = require('dgram');
socket.close();
}));
}

function checkBufferSizeError(type, size) {
const errorObj = {
code: 'ERR_SOCKET_BUFFER_SIZE',
type: Error,
message: 'Could not get or set buffer size: Error: EINVAL: ' +
`invalid argument, uv_${type}_buffer_size`
};
const functionName = `set${type.charAt(0).toUpperCase()}${type.slice(1)}` +
'BufferSize';
const socket = dgram.createSocket('udp4');
socket.bind(common.mustCall(() => {
assert.throws(() => {
socket[functionName](size);
}, common.expectsError(errorObj));
socket.close();
}));
}

checkBufferSizeError('recv', 2147483648);
checkBufferSizeError('send', 2147483648);

0 comments on commit f4899ac

Please sign in to comment.