mirror of
https://github.com/g4klx/ircDDBGateway.git
synced 2025-12-06 05:32:02 +01:00
Add a backoff timer for connections to aprs.fi.
This commit is contained in:
parent
b8fbf58815
commit
81a818b235
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2014,2018 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2010-2014,2018,2020 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
|
||||
|
|
@ -284,6 +284,8 @@ void CAPRSWriter::clock(unsigned int ms)
|
|||
{
|
||||
m_idTimer.clock(ms);
|
||||
|
||||
m_thread->clock(ms);
|
||||
|
||||
if (m_socket != NULL) {
|
||||
if (m_idTimer.hasExpired()) {
|
||||
pollGPS();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2014,2018 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2010-2014,2018,2020 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
|
||||
|
|
@ -34,6 +34,8 @@ m_socket(hostname, port, address),
|
|||
m_queue(20U),
|
||||
m_exit(false),
|
||||
m_connected(false),
|
||||
m_reconnectTimer(1000U),
|
||||
m_tries(0U),
|
||||
m_APRSReadCallback(NULL),
|
||||
m_filter(wxT("")),
|
||||
m_clientName(wxT("ircDDBGateway"))
|
||||
|
|
@ -59,6 +61,8 @@ m_socket(hostname, port, address),
|
|||
m_queue(20U),
|
||||
m_exit(false),
|
||||
m_connected(false),
|
||||
m_reconnectTimer(1000U),
|
||||
m_tries(0U),
|
||||
m_APRSReadCallback(NULL),
|
||||
m_filter(filter),
|
||||
m_clientName(clientName)
|
||||
|
|
@ -94,19 +98,28 @@ void* CAPRSWriterThread::Entry()
|
|||
wxLogMessage(wxT("Starting the APRS Writer thread"));
|
||||
|
||||
m_connected = connect();
|
||||
if (!m_connected) {
|
||||
wxLogError(wxT("Connect attempt to the APRS server has failed"));
|
||||
startReconnectionTimer();
|
||||
}
|
||||
|
||||
try {
|
||||
while (!m_exit) {
|
||||
if (!m_connected) {
|
||||
m_connected = connect();
|
||||
if (m_reconnectTimer.isRunning() && m_reconnectTimer.hasExpired()) {
|
||||
m_reconnectTimer.stop();
|
||||
|
||||
if (!m_connected){
|
||||
wxLogError(wxT("Reconnect attempt to the APRS server has failed"));
|
||||
Sleep(10000UL); // 10 secs
|
||||
m_connected = connect();
|
||||
if (!m_connected) {
|
||||
wxLogError(wxT("Reconnect attempt to the APRS server has failed"));
|
||||
startReconnectionTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_connected) {
|
||||
m_tries = 0U;
|
||||
|
||||
if(!m_queue.isEmpty()){
|
||||
char* p = m_queue.getData();
|
||||
|
||||
|
|
@ -120,6 +133,7 @@ void* CAPRSWriterThread::Entry()
|
|||
m_connected = false;
|
||||
m_socket.close();
|
||||
wxLogError(wxT("Connection to the APRS thread has failed"));
|
||||
startReconnectionTimer();
|
||||
}
|
||||
|
||||
delete[] p;
|
||||
|
|
@ -135,6 +149,7 @@ void* CAPRSWriterThread::Entry()
|
|||
m_connected = false;
|
||||
m_socket.close();
|
||||
wxLogError(wxT("Error when reading from the APRS server"));
|
||||
startReconnectionTimer();
|
||||
}
|
||||
|
||||
if(length > 0 && line.GetChar(0) != '#'//check if we have something and if that something is an APRS frame
|
||||
|
|
@ -201,6 +216,11 @@ void CAPRSWriterThread::stop()
|
|||
Wait();
|
||||
}
|
||||
|
||||
void CAPRSWriterThread::clock(unsigned int ms)
|
||||
{
|
||||
m_reconnectTimer.clock(ms);
|
||||
}
|
||||
|
||||
bool CAPRSWriterThread::connect()
|
||||
{
|
||||
bool ret = m_socket.open();
|
||||
|
|
@ -248,3 +268,14 @@ bool CAPRSWriterThread::connect()
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAPRSWriterThread::startReconnectionTimer()
|
||||
{
|
||||
// Clamp at a ten minutes reconnect time
|
||||
m_tries++;
|
||||
if (m_tries > 10U)
|
||||
m_tries = 10U;
|
||||
|
||||
m_reconnectTimer.setTimeout(m_tries * 60U);
|
||||
m_reconnectTimer.start();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2010,2011,2012,2018 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2010,2011,2012,2018,2020 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
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "TCPReaderWriterClient.h"
|
||||
#include "RingBuffer.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include <wx/wx.h>
|
||||
typedef void (*ReadAPRSFrameCallback)(const wxString&);
|
||||
|
|
@ -41,6 +42,8 @@ public:
|
|||
|
||||
virtual void stop();
|
||||
|
||||
void clock(unsigned int ms);
|
||||
|
||||
void setReadAPRSCallback(ReadAPRSFrameCallback cb);
|
||||
|
||||
private:
|
||||
|
|
@ -51,11 +54,14 @@ private:
|
|||
CRingBuffer<char*> m_queue;
|
||||
bool m_exit;
|
||||
bool m_connected;
|
||||
CTimer m_reconnectTimer;
|
||||
unsigned int m_tries;
|
||||
ReadAPRSFrameCallback m_APRSReadCallback;
|
||||
wxString m_filter;
|
||||
wxString m_clientName;
|
||||
|
||||
bool connect();
|
||||
void startReconnectionTimer();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue