From 751f2f9873c344a5571a495e493dea43db94fdb5 Mon Sep 17 00:00:00 2001 From: pupilTong Date: Sun, 15 May 2022 21:54:06 +0800 Subject: [PATCH] net: add ability to reset a tcp socket make it possible to forcibly rest a tcp socket: * add a new method `Socket.prototype.resetAndDestroy` * add a new flag `resetAndClosing` to make `_destroy` calls the `reset` instead of close while destroying a Socket. * add new methods `TCPWrap::Reset` to be a wrap of `uv_tcp_close_reset` * change `HandleWrap::state_` from private to protected. This is essential for keeping the same behaviour between `TCPWrap::Reset` and `HandleWrap::Close` Fixes: https://github.com/nodejs/node/issues/27428 --- src/tcp_wrap.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index bd3c92b75976dc..f3163fc84cd72f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -343,9 +343,8 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args, } void TCPWrap::Reset(const FunctionCallbackInfo& args) { TCPWrap* wrap; - ASSIGN_OR_RETURN_UNWRAP(&wrap, - args.Holder(), - args.GetReturnValue().Set(UV_EBADF)); + ASSIGN_OR_RETURN_UNWRAP( + &wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int err = wrap->Reset(args[0]); @@ -353,16 +352,15 @@ void TCPWrap::Reset(const FunctionCallbackInfo& args) { } int TCPWrap::Reset(Local close_callback) { - if (state_ != kInitialized) - return 0; + if (state_ != kInitialized) return 0; int err = uv_tcp_close_reset(&handle_, OnClose); state_ = kClosing; if (!err & !close_callback.IsEmpty() && close_callback->IsFunction() && !persistent().IsEmpty()) { - object()->Set(env()->context(), - env()->handle_onclose_symbol(), - close_callback).Check(); + object() + ->Set(env()->context(), env()->handle_onclose_symbol(), close_callback) + .Check(); } return err; }