Skip to content

Commit ecb0727

Browse files
authored
[ntcore] Client::Disconnect(): actually close connection (#5113)
1 parent 0d462a4 commit ecb0727

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

ntcore/src/main/native/cpp/NetworkClient.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class NCImpl {
5656
void StopDSClient();
5757

5858
virtual void TcpConnected(uv::Tcp& tcp) = 0;
59+
virtual void ForceDisconnect(std::string_view reason) = 0;
5960
virtual void Disconnect(std::string_view reason);
6061

6162
// invariants
@@ -99,6 +100,7 @@ class NCImpl3 : public NCImpl {
99100

100101
void HandleLocal();
101102
void TcpConnected(uv::Tcp& tcp) final;
103+
void ForceDisconnect(std::string_view reason) override;
102104
void Disconnect(std::string_view reason) override;
103105

104106
std::shared_ptr<net3::UvStreamConnection3> m_wire;
@@ -117,6 +119,7 @@ class NCImpl4 : public NCImpl {
117119
void HandleLocal();
118120
void TcpConnected(uv::Tcp& tcp) final;
119121
void WsConnected(wpi::WebSocket& ws, uv::Tcp& tcp);
122+
void ForceDisconnect(std::string_view reason) override;
120123
void Disconnect(std::string_view reason) override;
121124

122125
std::function<void(int64_t serverTimeOffset, int64_t rtt2, bool valid)>
@@ -346,6 +349,12 @@ void NCImpl3::TcpConnected(uv::Tcp& tcp) {
346349
tcp.StartRead();
347350
}
348351

352+
void NCImpl3::ForceDisconnect(std::string_view reason) {
353+
if (m_wire) {
354+
m_wire->Disconnect(reason);
355+
}
356+
}
357+
349358
void NCImpl3::Disconnect(std::string_view reason) {
350359
INFO("DISCONNECTED NT3 connection: {}", reason);
351360
m_clientImpl.reset();
@@ -491,6 +500,12 @@ void NCImpl4::WsConnected(wpi::WebSocket& ws, uv::Tcp& tcp) {
491500
});
492501
}
493502

503+
void NCImpl4::ForceDisconnect(std::string_view reason) {
504+
if (m_wire) {
505+
m_wire->Disconnect(reason);
506+
}
507+
}
508+
494509
void NCImpl4::Disconnect(std::string_view reason) {
495510
std::string realReason;
496511
if (m_wire) {
@@ -534,7 +549,7 @@ void NetworkClient::SetServers(
534549

535550
void NetworkClient::Disconnect() {
536551
m_impl->m_loopRunner.ExecAsync(
537-
[this](auto&) { m_impl->Disconnect("requested by application"); });
552+
[this](auto&) { m_impl->ForceDisconnect("requested by application"); });
538553
}
539554

540555
void NetworkClient::StartDSClient(unsigned int port) {
@@ -582,7 +597,7 @@ void NetworkClient3::SetServers(
582597

583598
void NetworkClient3::Disconnect() {
584599
m_impl->m_loopRunner.ExecAsync(
585-
[this](auto&) { m_impl->Disconnect("requested by application"); });
600+
[this](auto&) { m_impl->ForceDisconnect("requested by application"); });
586601
}
587602

588603
void NetworkClient3::StartDSClient(unsigned int port) {

0 commit comments

Comments
 (0)