From 387b5845b9da5aadfae57bd5c14a9fc36e580453 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 1 Feb 2019 00:49:56 -0300 Subject: [PATCH] Fix poll handling --- YSFGateway/YSFGateway.cpp | 5 +++-- YSFGateway/YSFNetwork.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 4cd6eee..21ae874 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -292,9 +292,10 @@ int CYSFGateway::run() } if (m_ysfNetwork != NULL && m_linkType == LINK_YSF && !m_exclude) { - m_ysfNetwork->write(buffer); - if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) + if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) { + m_ysfNetwork->write(buffer); m_inactivityTimer.start(); + } } if (m_fcsNetwork != NULL && m_linkType == LINK_FCS && !m_exclude) { diff --git a/YSFGateway/YSFNetwork.cpp b/YSFGateway/YSFNetwork.cpp index cb97f4f..91076d1 100644 --- a/YSFGateway/YSFNetwork.cpp +++ b/YSFGateway/YSFNetwork.cpp @@ -148,9 +148,13 @@ void CYSFNetwork::writeUnlink(unsigned int count) void CYSFNetwork::clock(unsigned int ms) { unsigned char buffer[BUFFER_LENGTH]; - in_addr address; unsigned int port; + + m_pollTimer.clock(ms); + if (m_pollTimer.isRunning() && m_pollTimer.hasExpired()) + writePoll(); + int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); if (length <= 0) return; @@ -158,10 +162,6 @@ void CYSFNetwork::clock(unsigned int ms) if (m_port == 0U) return; - m_pollTimer.clock(ms); - if (m_pollTimer.isRunning() && m_pollTimer.hasExpired()) - writePoll(); - if (address.s_addr != m_address.s_addr || port != m_port) return;