Skip to content

Commit

Permalink
net: add ability to reset a tcp socket
Browse files Browse the repository at this point in the history
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: nodejs#27428
  • Loading branch information
PupilTong authored and PupilTong committed May 18, 2022
1 parent 4338ec3 commit 751f2f9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,26 +343,24 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args,
}
void TCPWrap::Reset(const FunctionCallbackInfo<Value>& 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]);

args.GetReturnValue().Set(err);
}

int TCPWrap::Reset(Local<Value> 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;
}
Expand Down

0 comments on commit 751f2f9

Please sign in to comment.