aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2017-09-20 00:55:53 -0400
committercjihrig <cjihrig@gmail.com>2017-09-22 09:35:50 -0400
commit6983157adfb49d644fb27985f97f12a54fcc98e1 (patch)
treed5b17feb865dcc399ea736d0679ef82e6f4b74fc /src
parentf4899ac4c07658c1857fb3a41ef305cb2cfa40e4 (diff)
downloadandroid-node-v8-6983157adfb49d644fb27985f97f12a54fcc98e1.tar.gz
android-node-v8-6983157adfb49d644fb27985f97f12a54fcc98e1.tar.bz2
android-node-v8-6983157adfb49d644fb27985f97f12a54fcc98e1.zip
dgram: refactor SO_RCVBUF and SO_SNDBUF methods
This commit refactors the get/set send/receive buffer size methods in the following ways: - Use booleans instead of strings and numbers to differentiate between the send and receive buffers. - Reduce the amount of branching and complexity in the C++ code. Refs: https://github.com/nodejs/node/pull/13623 PR-URL: https://github.com/nodejs/node/pull/15483 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/udp_wrap.cc37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index 8a4b6ea966..5fb8daed74 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -233,31 +233,26 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(UV_EBADF));
CHECK(args[0]->IsUint32());
- CHECK(args[1]->IsUint32());
+ CHECK(args[1]->IsBoolean());
+ bool is_recv = args[1].As<v8::Boolean>()->Value();
+ const char* uv_func_name = is_recv ? "uv_recv_buffer_size" :
+ "uv_send_buffer_size";
- if (!args[0]->IsInt32()) {
- if (args[1].As<Uint32>()->Value() == 0)
- return env->ThrowUVException(UV_EINVAL, "uv_recv_buffer_size");
- else
- return env->ThrowUVException(UV_EINVAL, "uv_send_buffer_size");
- }
+ if (!args[0]->IsInt32())
+ return env->ThrowUVException(UV_EINVAL, uv_func_name);
- int err;
+ uv_handle_t* handle = reinterpret_cast<uv_handle_t*>(&wrap->handle_);
int size = static_cast<int>(args[0].As<Uint32>()->Value());
- if (args[1].As<Uint32>()->Value() == 0) {
- err = uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(&wrap->handle_),
- &size);
- } else {
- err = uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(&wrap->handle_),
- &size);
- }
+ int err;
+
+ if (is_recv)
+ err = uv_recv_buffer_size(handle, &size);
+ else
+ err = uv_send_buffer_size(handle, &size);
+
+ if (err != 0)
+ return env->ThrowUVException(err, uv_func_name);
- if (err != 0) {
- if (args[1].As<Uint32>()->Value() == 0)
- return env->ThrowUVException(err, "uv_recv_buffer_size");
- else
- return env->ThrowUVException(err, "uv_send_buffer_size");
- }
args.GetReturnValue().Set(size);
}