From f60cf52a0be87815ccbe1c8051bf439028dee3d3 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 21 Mar 2017 18:45:31 +0000 Subject: [PATCH] Handle idle timeouts and lost connections more gracefully. --- YSFGateway/Network.cpp | 2 +- YSFGateway/Network.h | 4 ++-- YSFGateway/WiresX.cpp | 3 ++- YSFGateway/WiresX.h | 5 +++-- YSFGateway/YSFGateway.cpp | 15 ++++++++++++--- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/YSFGateway/Network.cpp b/YSFGateway/Network.cpp index 02945a2..f643a43 100644 --- a/YSFGateway/Network.cpp +++ b/YSFGateway/Network.cpp @@ -93,7 +93,7 @@ void CNetwork::setDestination(const in_addr& address, unsigned int port) m_port = port; } -void CNetwork::setDestination() +void CNetwork::clearDestination() { m_address.s_addr = INADDR_NONE; m_port = 0U; diff --git a/YSFGateway/Network.h b/YSFGateway/Network.h index e5c90be..fc023c5 100644 --- a/YSFGateway/Network.h +++ b/YSFGateway/Network.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ public: bool open(); void setDestination(const in_addr& address, unsigned int port); - void setDestination(); + void clearDestination(); bool write(const unsigned char* data); diff --git a/YSFGateway/WiresX.cpp b/YSFGateway/WiresX.cpp index 9994dd4..ad30767 100644 --- a/YSFGateway/WiresX.cpp +++ b/YSFGateway/WiresX.cpp @@ -288,7 +288,8 @@ WX_STATUS CWiresX::processConnect(const unsigned char* source, const unsigned ch void CWiresX::processDisconnect(const unsigned char* source) { - ::LogDebug("Received Disconect from %10.10s", source); + if (source != NULL) + ::LogDebug("Received Disconect from %10.10s", source); m_reflector = NULL; diff --git a/YSFGateway/WiresX.h b/YSFGateway/WiresX.h index 5593245..0c83379 100644 --- a/YSFGateway/WiresX.h +++ b/YSFGateway/WiresX.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,6 +55,8 @@ public: CYSFReflector* getReflector() const; CYSFReflector* getReflector(const std::string& id); + void processDisconnect(const unsigned char* source = NULL); + void clock(unsigned int ms); private: @@ -79,7 +81,6 @@ private: std::string m_search; WX_STATUS processConnect(const unsigned char* source, const unsigned char* data); - void processDisconnect(const unsigned char* source); void processDX(const unsigned char* source); void processAll(const unsigned char* source, const unsigned char* data); diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 87ed8b0..4216444 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -289,7 +289,7 @@ int CYSFGateway::run() m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink(); - m_netNetwork->setDestination(); + m_netNetwork->clearDestination(); inactivityTimer.stop(); lostTimer.stop(); @@ -344,10 +344,13 @@ int CYSFGateway::run() if (m_linked) { LogMessage("Disconnecting due to inactivity"); + if (m_wiresX != NULL) + m_wiresX->processDisconnect(); + m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink(); - m_netNetwork->setDestination(); + m_netNetwork->clearDestination(); lostTimer.stop(); pollTimer.stop(); @@ -361,10 +364,16 @@ int CYSFGateway::run() lostTimer.clock(ms); if (lostTimer.isRunning() && lostTimer.hasExpired()) { LogWarning("Link has failed, polls lost"); - m_netNetwork->setDestination(); + + if (m_wiresX != NULL) + m_wiresX->processDisconnect(); + + m_netNetwork->clearDestination(); + inactivityTimer.stop(); lostTimer.stop(); pollTimer.stop(); + m_linked = false; }