| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e457d89 commit 72340c9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,25 @@ using v8::Uint32; | |||
| 52 | 52 | using v8::Undefined; | |
| 53 | 53 | using v8::Value; | |
| 54 | 54 | ||
| 55 | + namespace { | ||
| 56 | + template <int (*fn)(uv_udp_t*, int)> | ||
| 57 | + void SetLibuvInt32(const FunctionCallbackInfo<Value>& args) { | ||
| 58 | + UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); | ||
| 59 | + if (wrap == nullptr) { | ||
| 60 | + args.GetReturnValue().Set(UV_EBADF); | ||
| 61 | + return; | ||
| 62 | + } | ||
| 63 | + Environment* env = wrap->env(); | ||
| 64 | + CHECK_EQ(args.Length(), 1); | ||
| 65 | + int flag; | ||
| 66 | + if (!args[0]->Int32Value(env->context()).To(&flag)) { | ||
| 67 | + return; | ||
| 68 | + } | ||
| 69 | + int err = fn(wrap->GetLibuvHandle(), flag); | ||
| 70 | + args.GetReturnValue().Set(err); | ||
| 71 | + } | ||
| 72 | + } // namespace | ||
| 73 | + | ||
| 55 | 74 | class SendWrap : public ReqWrap<uv_udp_send_t> { | |
| 56 | 75 | public: | |
| 57 | 76 | SendWrap(Environment* env, Local<Object> req_wrap_obj, bool have_callback); | |
@@ -177,10 +196,15 @@ void UDPWrap::Initialize(Local<Object> target, | |||
| 177 | 196 | SetProtoMethod( | |
| 178 | 197 | isolate, t, "dropSourceSpecificMembership", DropSourceSpecificMembership); | |
| 179 | 198 | SetProtoMethod(isolate, t, "setMulticastInterface", SetMulticastInterface); | |
| 180 | - SetProtoMethod(isolate, t, "setMulticastTTL", SetMulticastTTL); | ||
| 181 | - SetProtoMethod(isolate, t, "setMulticastLoopback", SetMulticastLoopback); | ||
| 182 | - SetProtoMethod(isolate, t, "setBroadcast", SetBroadcast); | ||
| 183 | - SetProtoMethod(isolate, t, "setTTL", SetTTL); | ||
| 199 | + SetProtoMethod( | ||
| 200 | + isolate, t, "setMulticastTTL", SetLibuvInt32<uv_udp_set_multicast_ttl>); | ||
| 201 | + SetProtoMethod(isolate, | ||
| 202 | + t, | ||
| 203 | + "setMulticastLoopback", | ||
| 204 | + SetLibuvInt32<uv_udp_set_multicast_loop>); | ||
| 205 | + SetProtoMethod( | ||
| 206 | + isolate, t, "setBroadcast", SetLibuvInt32<uv_udp_set_broadcast>); | ||
| 207 | + SetProtoMethod(isolate, t, "setTTL", SetLibuvInt32<uv_udp_set_ttl>); | ||
| 184 | 208 | SetProtoMethod(isolate, t, "bufferSize", BufferSize); | |
| 185 | 209 | SetProtoMethodNoSideEffect(isolate, t, "getSendQueueSize", GetSendQueueSize); | |
| 186 | 210 | SetProtoMethodNoSideEffect( | |
@@ -373,30 +397,6 @@ void UDPWrap::Disconnect(const FunctionCallbackInfo<Value>& args) { | |||
| 373 | 397 | args.GetReturnValue().Set(err); | |
| 374 | 398 | } | |
| 375 | 399 | ||
| 376 | - #define X(name, fn) \ | ||
| 377 | - void UDPWrap::name(const FunctionCallbackInfo<Value>& args) { \ | ||
| 378 | - UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); \ | ||
| 379 | - if (wrap == nullptr) { \ | ||
| 380 | - args.GetReturnValue().Set(UV_EBADF); \ | ||
| 381 | - return; \ | ||
| 382 | - } \ | ||
| 383 | - Environment* env = wrap->env(); \ | ||
| 384 | - CHECK_EQ(args.Length(), 1); \ | ||
| 385 | - int flag; \ | ||
| 386 | - if (!args[0]->Int32Value(env->context()).To(&flag)) { \ | ||
| 387 | - return; \ | ||
| 388 | - } \ | ||
| 389 | - int err = fn(&wrap->handle_, flag); \ | ||
| 390 | - args.GetReturnValue().Set(err); \ | ||
| 391 | - } | ||
| 392 | - | ||
| 393 | - X(SetTTL, uv_udp_set_ttl) | ||
| 394 | - X(SetBroadcast, uv_udp_set_broadcast) | ||
| 395 | - X(SetMulticastTTL, uv_udp_set_multicast_ttl) | ||
| 396 | - X(SetMulticastLoopback, uv_udp_set_multicast_loop) | ||
| 397 | - | ||
| 398 | - #undef X | ||
| 399 | - | ||
| 400 | 400 | void UDPWrap::SetMulticastInterface(const FunctionCallbackInfo<Value>& args) { | |
| 401 | 401 | UDPWrap* wrap; | |
| 402 | 402 | ASSIGN_OR_RETURN_UNWRAP(&wrap, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,11 +144,6 @@ class UDPWrap final : public HandleWrap, | |||
| 144 | 144 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 145 | 145 | static void SetMulticastInterface( | |
| 146 | 146 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 147 | - static void SetMulticastTTL(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 148 | - static void SetMulticastLoopback( | ||
| 149 | - const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 150 | - static void SetBroadcast(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 151 | - static void SetTTL(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 152 | 147 | static void BufferSize(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 153 | 148 | static void GetSendQueueSize(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 154 | 149 | static void GetSendQueueCount( | |
@@ -175,6 +170,8 @@ class UDPWrap final : public HandleWrap, | |||
| 175 | 170 | ||
| 176 | 171 | AsyncWrap* GetAsyncWrap() override; | |
| 177 | 172 | ||
| 173 | + inline uv_udp_t* GetLibuvHandle() { return &handle_; } | ||
| 174 | + | ||
| 178 | 175 | static v8::MaybeLocal<v8::Object> Instantiate(Environment* env, | |
| 179 | 176 | AsyncWrap* parent, | |
| 180 | 177 | SocketType type); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments