mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
dgram: migrate bufferSize to use internal/errors
PR-URL: https://github.com/nodejs/node/pull/16567 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
1 parent
3d9d84940a
commit
9ad994befb
3 files changed
+15
-10
No files matched your search
+6
-4
@@ -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*/) {
|
||||
|
||||
+8
-4
@@ -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());
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user