diff options
author | Ouyang Yadong <oyydoibh@gmail.com> | 2018-07-29 17:41:11 +0300 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-08-06 12:05:51 +0300 |
commit | 2bea9cefbc10ed1dd497bbae61c07d971da287dd (patch) | |
tree | 02bfcbc3fcf39fe7524f9271762617f23e107925 /src/udp_wrap.cc | |
parent | 214844ea4e561b0f77e97643d28b251cdc574089 (diff) |
dgram: implement socket.bind({ fd })
dgram: Implement binding an existing `fd`. Allow pass a `fd` property
to `socket.bind()` in dgram.
src: Add `UDPWrap::Open`
PR-URL: https://github.com/nodejs/node/pull/21745
Fixes: https://github.com/nodejs/node/issues/14961
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/udp_wrap.cc')
-rw-r--r-- | src/udp_wrap.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 2ef5c613587..9bcf6ceb7b3 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -117,6 +117,7 @@ void UDPWrap::Initialize(Local<Object> target, Local<FunctionTemplate>(), attributes); + env->SetProtoMethod(t, "open", Open); env->SetProtoMethod(t, "bind", Bind); env->SetProtoMethod(t, "send", Send); env->SetProtoMethod(t, "bind6", Bind6); @@ -206,6 +207,18 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) { } +void UDPWrap::Open(const FunctionCallbackInfo<Value>& args) { + UDPWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, + args.Holder(), + args.GetReturnValue().Set(UV_EBADF)); + int fd = static_cast<int>(args[0]->IntegerValue()); + int err = uv_udp_open(&wrap->handle_, fd); + + args.GetReturnValue().Set(err); +} + + void UDPWrap::Bind(const FunctionCallbackInfo<Value>& args) { DoBind(args, AF_INET); } |