src: simplify `TCPWrap::Connect` signature · nodejs/node@b5ca5ad
@@ -372,10 +372,11 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
372372}
373373374374template <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)) {
379380 TCPWrap* wrap;
380381ASSIGN_OR_RETURN_UNWRAP(
381382 &wrap, args.This(), args.GetReturnValue().Set(UV_EBADF));
@@ -424,29 +425,18 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
424425}
425426426427void 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);
433429}
434430435431void 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);
444433}
445434446435template <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)) {
450440 Environment* env = Environment::GetCurrent(args);
451441452442 TCPWrap* wrap;
@@ -456,11 +446,14 @@ void TCPWrap::Connect(
456446CHECK(args[0]->IsObject());
457447CHECK(args[1]->IsString());
458448449+int port;
450+if (!args[2]->Int32Value(env->context()).To(&port)) return;
451+459452 Local<Object> req_wrap_obj = args[0].As<Object>();
460453 node::Utf8Value ip_address(env->isolate(), args[1]);
461454462455 T addr;
463-int err = uv_ip_addr(*ip_address, &addr);
456+int err = uv_ip_addr(*ip_address, port, &addr);
464457465458if (err == 0) {
466459 AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap);