1
0
Fork 0

Handle idle timeouts and lost connections more gracefully.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 2423a67ae6
commit f60cf52a0b

@ -93,7 +93,7 @@ void CNetwork::setDestination(const in_addr& address, unsigned int port)
m_port = port; m_port = port;
} }
void CNetwork::setDestination() void CNetwork::clearDestination()
{ {
m_address.s_addr = INADDR_NONE; m_address.s_addr = INADDR_NONE;
m_port = 0U; m_port = 0U;

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -35,7 +35,7 @@ public:
bool open(); bool open();
void setDestination(const in_addr& address, unsigned int port); void setDestination(const in_addr& address, unsigned int port);
void setDestination(); void clearDestination();
bool write(const unsigned char* data); bool write(const unsigned char* data);

@ -288,7 +288,8 @@ WX_STATUS CWiresX::processConnect(const unsigned char* source, const unsigned ch
void CWiresX::processDisconnect(const unsigned char* source) 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; m_reflector = NULL;

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -55,6 +55,8 @@ public:
CYSFReflector* getReflector() const; CYSFReflector* getReflector() const;
CYSFReflector* getReflector(const std::string& id); CYSFReflector* getReflector(const std::string& id);
void processDisconnect(const unsigned char* source = NULL);
void clock(unsigned int ms); void clock(unsigned int ms);
private: private:
@ -79,7 +81,6 @@ private:
std::string m_search; std::string m_search;
WX_STATUS processConnect(const unsigned char* source, const unsigned char* data); WX_STATUS processConnect(const unsigned char* source, const unsigned char* data);
void processDisconnect(const unsigned char* source);
void processDX(const unsigned char* source); void processDX(const unsigned char* source);
void processAll(const unsigned char* source, const unsigned char* data); void processAll(const unsigned char* source, const unsigned char* data);

@ -289,7 +289,7 @@ int CYSFGateway::run()
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->setDestination(); m_netNetwork->clearDestination();
inactivityTimer.stop(); inactivityTimer.stop();
lostTimer.stop(); lostTimer.stop();
@ -344,10 +344,13 @@ int CYSFGateway::run()
if (m_linked) { if (m_linked) {
LogMessage("Disconnecting due to inactivity"); LogMessage("Disconnecting due to inactivity");
if (m_wiresX != NULL)
m_wiresX->processDisconnect();
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->setDestination(); m_netNetwork->clearDestination();
lostTimer.stop(); lostTimer.stop();
pollTimer.stop(); pollTimer.stop();
@ -361,10 +364,16 @@ int CYSFGateway::run()
lostTimer.clock(ms); lostTimer.clock(ms);
if (lostTimer.isRunning() && lostTimer.hasExpired()) { if (lostTimer.isRunning() && lostTimer.hasExpired()) {
LogWarning("Link has failed, polls lost"); LogWarning("Link has failed, polls lost");
m_netNetwork->setDestination();
if (m_wiresX != NULL)
m_wiresX->processDisconnect();
m_netNetwork->clearDestination();
inactivityTimer.stop(); inactivityTimer.stop();
lostTimer.stop(); lostTimer.stop();
pollTimer.stop(); pollTimer.stop();
m_linked = false; m_linked = false;
} }

Loading…
Cancel
Save