Merge pull request #11 from dd5xl/master

Moved Flo's variable delay code to recover() to prevent re-logins at f…
This commit is contained in:
Florian (DF2ET) 2018-08-24 21:54:12 +02:00 committed by GitHub
commit 18815b7437
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -278,6 +278,9 @@ int CDAPNETGateway::run()
}
bool ok = m_dapnetNetwork->read();
if (!ok)
recover();
/*
if (!ok) {
int i = 0;
const unsigned int backoff[] = {
@ -290,7 +293,7 @@ int CDAPNETGateway::run()
i++;
}
}
*/
CPOCSAGMessage* message = m_dapnetNetwork->readMessage();
if (message != NULL) {
bool found = true;
@ -404,14 +407,21 @@ void CDAPNETGateway::sendMessages()
bool CDAPNETGateway::recover()
{
const unsigned int backoff[] = {2000u, 4000u, 8000u, 10000u, 20000u, 60000u, 120000u, 240000u, 480000u, 600000u};
int i=0;
for (;;) {
m_dapnetNetwork->close();
CThread::sleep(backoff[i]);
bool ok = m_dapnetNetwork->open();
if (ok) {
ok = m_dapnetNetwork->login();
if (ok)
return true;
}
if (i < 9)
i++;
}
return false;

View file

@ -69,6 +69,8 @@ bool CDAPNETNetwork::read()
unsigned char buffer[BUFFER_LENGTH];
int length = m_socket.read(buffer, BUFFER_LENGTH, 0U);
if (length < 0)
LogMessage ("socket.read: received error %d", length);
if (length == -1) // Error
return false;
if (length == -2) // Connection lost