| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ca02af1 commit b5ca5ad
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -372,10 +372,11 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) { | |||
| 372 | 372 | } | |
| 373 | 373 | ||
| 374 | 374 | template <typename T> | |
| 375 | - void TCPWrap::Bind( | ||
| 376 | - const FunctionCallbackInfo<Value>& args, | ||
| 377 | - int family, | ||
| 378 | - std::function<int(const char* ip_address, int port, T* addr)> uv_ip_addr) { | ||
| 375 | + void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args, | ||
| 376 | + int family, | ||
| 377 | + int (*uv_ip_addr)(const char* ip_address, | ||
| 378 | + int port, | ||
| 379 | + T* addr)) { | ||
| 379 | 380 | TCPWrap* wrap; | |
| 380 | 381 | ASSIGN_OR_RETURN_UNWRAP( | |
| 381 | 382 | &wrap, args.This(), args.GetReturnValue().Set(UV_EBADF)); | |
@@ -424,29 +425,18 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) { | |||
| 424 | 425 | } | |
| 425 | 426 | ||
| 426 | 427 | void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) { | |
| 427 | - CHECK(args[2]->IsUint32()); | ||
| 428 | - // explicit cast to fit to libuv's type expectation | ||
| 429 | - int port = static_cast<int>(args[2].As<Uint32>()->Value()); | ||
| 430 | - Connect<sockaddr_in>(args, [port](const char* ip_address, sockaddr_in* addr) { | ||
| 431 | - return uv_ip4_addr(ip_address, port, addr); | ||
| 432 | - }); | ||
| 428 | + Connect<sockaddr_in>(args, uv_ip4_addr); | ||
| 433 | 429 | } | |
| 434 | 430 | ||
| 435 | 431 | void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) { | |
| 436 | - Environment* env = Environment::GetCurrent(args); | ||
| 437 | - CHECK(args[2]->IsUint32()); | ||
| 438 | - int port; | ||
| 439 | - if (!args[2]->Int32Value(env->context()).To(&port)) return; | ||
| 440 | - Connect<sockaddr_in6>(args, | ||
| 441 | - [port](const char* ip_address, sockaddr_in6* addr) { | ||
| 442 | - return uv_ip6_addr(ip_address, port, addr); | ||
| 443 | - }); | ||
| 432 | + Connect<sockaddr_in6>(args, uv_ip6_addr); | ||
| 444 | 433 | } | |
| 445 | 434 | ||
| 446 | 435 | template <typename T> | |
| 447 | - void TCPWrap::Connect( | ||
| 448 | - const FunctionCallbackInfo<Value>& args, | ||
| 449 | - std::function<int(const char* ip_address, T* addr)> uv_ip_addr) { | ||
| 436 | + void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args, | ||
| 437 | + int (*uv_ip_addr)(const char* ip_address, | ||
| 438 | + int port, | ||
| 439 | + T* addr)) { | ||
| 450 | 440 | Environment* env = Environment::GetCurrent(args); | |
| 451 | 441 | ||
| 452 | 442 | TCPWrap* wrap; | |
@@ -456,11 +446,14 @@ void TCPWrap::Connect( | |||
| 456 | 446 | CHECK(args[0]->IsObject()); | |
| 457 | 447 | CHECK(args[1]->IsString()); | |
| 458 | 448 | ||
| 449 | + int port; | ||
| 450 | + if (!args[2]->Int32Value(env->context()).To(&port)) return; | ||
| 451 | + | ||
| 459 | 452 | Local<Object> req_wrap_obj = args[0].As<Object>(); | |
| 460 | 453 | node::Utf8Value ip_address(env->isolate(), args[1]); | |
| 461 | 454 | ||
| 462 | 455 | T addr; | |
| 463 | - int err = uv_ip_addr(*ip_address, &addr); | ||
| 456 | + int err = uv_ip_addr(*ip_address, port, &addr); | ||
| 464 | 457 | ||
| 465 | 458 | if (err == 0) { | |
| 466 | 459 | AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,13 +83,16 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> { | |||
| 83 | 83 | static void Connect6(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 84 | 84 | template <typename T> | |
| 85 | 85 | static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args, | |
| 86 | - std::function<int(const char* ip_address, T* addr)> uv_ip_addr); | ||
| 86 | + int (*uv_ip_addr)(const char* ip_address, | ||
| 87 | + int port, | ||
| 88 | + T* addr)); | ||
| 87 | 89 | static void Open(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 88 | 90 | template <typename T> | |
| 89 | - static void Bind( | ||
| 90 | - const v8::FunctionCallbackInfo<v8::Value>& args, | ||
| 91 | - int family, | ||
| 92 | - std::function<int(const char* ip_address, int port, T* addr)> uv_ip_addr); | ||
| 91 | + static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args, | ||
| 92 | + int family, | ||
| 93 | + int (*uv_ip_addr)(const char* ip_address, | ||
| 94 | + int port, | ||
| 95 | + T* addr)); | ||
| 93 | 96 | static void Reset(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 94 | 97 | int Reset(v8::Local<v8::Value> close_callback = v8::Local<v8::Value>()); | |
| 95 | 98 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments