Skip to content

Commit

Permalink
dgram: migrate bufferSize to use internal/errors
Browse files Browse the repository at this point in the history
PR-URL: #16567
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
jasnell committed Nov 2, 2017
1 parent 3d9d849 commit 9ad994b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ function bufferSize(self, size, buffer) {
if (size >>> 0 !== size)
throw new errors.TypeError('ERR_SOCKET_BAD_BUFFER_SIZE');

try {
return self._handle.bufferSize(size, buffer);
} catch (e) {
throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e);
const ctx = {};
const ret = self._handle.bufferSize(size, buffer, ctx);
if (ret === undefined) {
throw new errors.Error('ERR_SOCKET_BUFFER_SIZE',
new errors.SystemError(ctx));
}
return ret;
}

Socket.prototype.bind = function(port_, address_ /*, callback*/) {
Expand Down
12 changes: 8 additions & 4 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
const char* uv_func_name = is_recv ? "uv_recv_buffer_size" :
"uv_send_buffer_size";

if (!args[0]->IsInt32())
return env->ThrowUVException(UV_EINVAL, uv_func_name);
if (!args[0]->IsInt32()) {
env->CollectUVExceptionInfo(args[2], UV_EINVAL, uv_func_name);
return args.GetReturnValue().SetUndefined();
}

uv_handle_t* handle = reinterpret_cast<uv_handle_t*>(&wrap->handle_);
int size = static_cast<int>(args[0].As<Uint32>()->Value());
Expand All @@ -246,8 +248,10 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
else
err = uv_send_buffer_size(handle, &size);

if (err != 0)
return env->ThrowUVException(err, uv_func_name);
if (err != 0) {
env->CollectUVExceptionInfo(args[2], err, uv_func_name);
return args.GetReturnValue().SetUndefined();
}

args.GetReturnValue().Set(size);
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-dgram-socket-buffer-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ 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`
message: /^Could not get or set buffer size:.*$/
};
const functionName = `set${type.charAt(0).toUpperCase()}${type.slice(1)}` +
'BufferSize';
Expand Down

0 comments on commit 9ad994b

Please sign in to comment.