Skip to content

Commit

Permalink
Disconnection bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dujeonglee committed Jul 14, 2017
1 parent 8e403a2 commit 171848a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
53 changes: 27 additions & 26 deletions tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,8 @@ void TransmissionSession::SendPing()
if(TimeSinceLastPongTime.count() > Parameter::CONNECTION_TIMEOUT)
{
TransmissionSession const * self = this;
std::cout<<"Pong Timeout...Client is disconnected.["<<TimeSinceLastPongTime.count()<<"]"<<std::endl;
std::thread DisconnectThread = std::thread([self](){
//self->c_Transmission->Disconnect(self->c_IPv4, self->c_Port);
});
DisconnectThread.detach();
std::cout<<"Client is disconnected. No response for "<<TimeSinceLastPongTime.count()<<" sec."<<std::endl;
self->c_Transmission->Disconnect(self->c_Addr);
return;
}

Expand Down Expand Up @@ -562,32 +559,36 @@ void Transmission::WaitUntilTxIsCompleted(const DataStructures::AddressType Addr
}
}

bool Transmission::Disconnect(const DataStructures::AddressType Addr)
void Transmission::Disconnect(const DataStructures::AddressType Addr)
{
const DataStructures::SessionKey key = DataStructures::GetSessionKey((sockaddr*)&Addr.Addr, Addr.AddrLength);
TransmissionSession** pp_session = nullptr;
{
std::unique_lock< std::mutex > lock(m_Lock);

pp_session = m_Sessions.GetPtr(key);
if(pp_session == nullptr)
Transmission* const self = this;
std::thread DisconnectThread = std::thread([self, Addr](){
const DataStructures::SessionKey key = DataStructures::GetSessionKey((sockaddr*)&Addr.Addr, Addr.AddrLength);
TransmissionSession** pp_session = nullptr;
{
return false;
std::unique_lock< std::mutex > lock(self->m_Lock);

pp_session = self->m_Sessions.GetPtr(key);
if(pp_session == nullptr)
{
return false;
}
}
}
do
{
(*pp_session)->m_IsConnected = false;
for(auto i = 0 ; i < Parameter::MAXIMUM_NUMBER_OF_CONCURRENT_RETRANSMISSION*2 ; i++)
do
{
(*pp_session)->m_AckList[i] = true;
}
}while(0 < (*pp_session)->m_ConcurrentRetransmissions);
m_Sessions.Remove(key, [](TransmissionSession*&session){
session->m_Timer.Stop();
delete session;
(*pp_session)->m_IsConnected = false;
for(auto i = 0 ; i < Parameter::MAXIMUM_NUMBER_OF_CONCURRENT_RETRANSMISSION*2 ; i++)
{
(*pp_session)->m_AckList[i] = true;
}
}while(0 < (*pp_session)->m_ConcurrentRetransmissions);
self->m_Sessions.Remove(key, [](TransmissionSession*&session){
session->m_Timer.Stop();
delete session;
});
return true;
});
return true;
DisconnectThread.detach();
}

/* OK */
Expand Down
2 changes: 1 addition & 1 deletion tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Transmission
bool Send(const DataStructures::AddressType Addr, uint8_t* buffer, uint16_t buffersize/*, bool reqack*/);
bool Flush(const DataStructures::AddressType Addr);
void WaitUntilTxIsCompleted(const DataStructures::AddressType Addr);
bool Disconnect(const DataStructures::AddressType Addr);
void Disconnect(const DataStructures::AddressType Addr);
public:
void RxHandler(uint8_t* buffer, uint16_t size, const sockaddr* const sender_addr, const uint32_t sender_addr_len);
};
Expand Down

0 comments on commit 171848a

Please sign in to comment.