From c7c7112bb7ebd49d78e390c29892e5102fe72bea Mon Sep 17 00:00:00 2001 From: maschinist Date: Fri, 24 Aug 2018 20:24:42 +0200 Subject: [PATCH] Moved Flo's variable delay code to recover() to prevent re-login at full speed --- DAPNETGateway.cpp | 12 +++++++++++- DAPNETNetwork.cpp | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DAPNETGateway.cpp b/DAPNETGateway.cpp index 41dc7c7..813eb37 100644 --- a/DAPNETGateway.cpp +++ b/DAPNETGateway.cpp @@ -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, 10000, 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; diff --git a/DAPNETNetwork.cpp b/DAPNETNetwork.cpp index e3dabb2..2d6842f 100644 --- a/DAPNETNetwork.cpp +++ b/DAPNETNetwork.cpp @@ -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