Skip to content

Commit 171848a

Browse files
committed
Disconnection bug fix
1 parent 8e403a2 commit 171848a

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

tx.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,8 @@ void TransmissionSession::SendPing()
336336
if(TimeSinceLastPongTime.count() > Parameter::CONNECTION_TIMEOUT)
337337
{
338338
TransmissionSession const * self = this;
339-
std::cout<<"Pong Timeout...Client is disconnected.["<<TimeSinceLastPongTime.count()<<"]"<<std::endl;
340-
std::thread DisconnectThread = std::thread([self](){
341-
//self->c_Transmission->Disconnect(self->c_IPv4, self->c_Port);
342-
});
343-
DisconnectThread.detach();
339+
std::cout<<"Client is disconnected. No response for "<<TimeSinceLastPongTime.count()<<" sec."<<std::endl;
340+
self->c_Transmission->Disconnect(self->c_Addr);
344341
return;
345342
}
346343

@@ -562,32 +559,36 @@ void Transmission::WaitUntilTxIsCompleted(const DataStructures::AddressType Addr
562559
}
563560
}
564561

565-
bool Transmission::Disconnect(const DataStructures::AddressType Addr)
562+
void Transmission::Disconnect(const DataStructures::AddressType Addr)
566563
{
567-
const DataStructures::SessionKey key = DataStructures::GetSessionKey((sockaddr*)&Addr.Addr, Addr.AddrLength);
568-
TransmissionSession** pp_session = nullptr;
569-
{
570-
std::unique_lock< std::mutex > lock(m_Lock);
571-
572-
pp_session = m_Sessions.GetPtr(key);
573-
if(pp_session == nullptr)
564+
Transmission* const self = this;
565+
std::thread DisconnectThread = std::thread([self, Addr](){
566+
const DataStructures::SessionKey key = DataStructures::GetSessionKey((sockaddr*)&Addr.Addr, Addr.AddrLength);
567+
TransmissionSession** pp_session = nullptr;
574568
{
575-
return false;
569+
std::unique_lock< std::mutex > lock(self->m_Lock);
570+
571+
pp_session = self->m_Sessions.GetPtr(key);
572+
if(pp_session == nullptr)
573+
{
574+
return false;
575+
}
576576
}
577-
}
578-
do
579-
{
580-
(*pp_session)->m_IsConnected = false;
581-
for(auto i = 0 ; i < Parameter::MAXIMUM_NUMBER_OF_CONCURRENT_RETRANSMISSION*2 ; i++)
577+
do
582578
{
583-
(*pp_session)->m_AckList[i] = true;
584-
}
585-
}while(0 < (*pp_session)->m_ConcurrentRetransmissions);
586-
m_Sessions.Remove(key, [](TransmissionSession*&session){
587-
session->m_Timer.Stop();
588-
delete session;
579+
(*pp_session)->m_IsConnected = false;
580+
for(auto i = 0 ; i < Parameter::MAXIMUM_NUMBER_OF_CONCURRENT_RETRANSMISSION*2 ; i++)
581+
{
582+
(*pp_session)->m_AckList[i] = true;
583+
}
584+
}while(0 < (*pp_session)->m_ConcurrentRetransmissions);
585+
self->m_Sessions.Remove(key, [](TransmissionSession*&session){
586+
session->m_Timer.Stop();
587+
delete session;
588+
});
589+
return true;
589590
});
590-
return true;
591+
DisconnectThread.detach();
591592
}
592593

593594
/* OK */

tx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Transmission
101101
bool Send(const DataStructures::AddressType Addr, uint8_t* buffer, uint16_t buffersize/*, bool reqack*/);
102102
bool Flush(const DataStructures::AddressType Addr);
103103
void WaitUntilTxIsCompleted(const DataStructures::AddressType Addr);
104-
bool Disconnect(const DataStructures::AddressType Addr);
104+
void Disconnect(const DataStructures::AddressType Addr);
105105
public:
106106
void RxHandler(uint8_t* buffer, uint16_t size, const sockaddr* const sender_addr, const uint32_t sender_addr_len);
107107
};

0 commit comments

Comments
 (0)