1
0
Fork 0

Reflector clean ups and fix memory leaks.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 6782b4bf0d
commit 06580ba87a

@ -191,8 +191,8 @@ void CYSFReflector::run()
unsigned int len = network.readData(buffer, 200U, address, port); unsigned int len = network.readData(buffer, 200U, address, port);
if (len > 0U) { if (len > 0U) {
CYSFRepeater* rpt = findRepeater(address, port);
if (::memcmp(buffer, "YSFP", 4U) == 0) { if (::memcmp(buffer, "YSFP", 4U) == 0) {
CYSFRepeater* rpt = findRepeater(address, port);
if (rpt == NULL) { if (rpt == NULL) {
rpt = new CYSFRepeater; rpt = new CYSFRepeater;
rpt->m_callsign = std::string((char*)(buffer + 4U), 10U); rpt->m_callsign = std::string((char*)(buffer + 4U), 10U);
@ -204,62 +204,61 @@ void CYSFReflector::run()
} }
rpt->m_timer.start(); rpt->m_timer.start();
network.writePoll(address, port); network.writePoll(address, port);
} else if (::memcmp(buffer + 0U, "YSFU", 4U) == 0) { } else if (::memcmp(buffer + 0U, "YSFU", 4U) == 0 && rpt != NULL) {
CYSFRepeater* rpt = findRepeater(address, port); LogMessage("Removing %s (unlinked)", rpt->m_callsign.c_str());
if (rpt != NULL) { for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
LogMessage("Removing %s (unlinked)", rpt->m_callsign.c_str()); CYSFRepeater* itRpt = *it;
std::vector<CYSFRepeater*>::iterator it = std::find(m_repeaters.begin(), m_repeaters.end(), rpt); if (itRpt->m_address.s_addr == rpt->m_address.s_addr && itRpt->m_port == rpt->m_port) {
if (it != m_repeaters.end())
m_repeaters.erase(it); m_repeaters.erase(it);
network.setCount(m_repeaters.size()); delete itRpt;
break;
}
} }
} else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) { network.setCount(m_repeaters.size());
CYSFRepeater* rpt = findRepeater(address, port); } else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0 && rpt != NULL) {
if (rpt != NULL) { if (!watchdogTimer.isRunning()) {
if (!watchdogTimer.isRunning()) { ::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH);
::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH);
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0)
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0) ::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH);
else
::memcpy(src, "??????????", YSF_CALLSIGN_LENGTH);
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0)
::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH);
else
::memcpy(dst, "??????????", YSF_CALLSIGN_LENGTH);
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U);
} else {
if (::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) {
bool changed = false;
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH); ::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH);
else changed = true;
::memcpy(src, "??????????", YSF_CALLSIGN_LENGTH); }
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0) if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH); ::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH);
else changed = true;
::memcpy(dst, "??????????", YSF_CALLSIGN_LENGTH);
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U);
} else {
if (::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) {
bool changed = false;
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH);
changed = true;
}
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH);
changed = true;
}
if (changed)
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U);
} }
if (changed)
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U);
} }
}
watchdogTimer.start(); watchdogTimer.start();
for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
if ((*it)->m_address.s_addr != address.s_addr && (*it)->m_port != port) if ((*it)->m_address.s_addr != address.s_addr && (*it)->m_port != port)
network.writeData(buffer, (*it)->m_address, (*it)->m_port); network.writeData(buffer, (*it)->m_address, (*it)->m_port);
} }
if ((buffer[34U] & 0x01U) == 0x01U) { if ((buffer[34U] & 0x01U) == 0x01U) {
LogMessage("Received end of transmission"); LogMessage("Received end of transmission");
watchdogTimer.stop(); watchdogTimer.stop();
}
} }
} }
} }
@ -279,9 +278,11 @@ void CYSFReflector::run()
(*it)->m_timer.clock(ms); (*it)->m_timer.clock(ms);
for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
if ((*it)->m_timer.hasExpired()) { CYSFRepeater* itRpt = *it;
LogMessage("Removing %s (polls lost)", (*it)->m_callsign.c_str()); if (itRpt->m_timer.hasExpired()) {
LogMessage("Removing %s (polls lost)", itRpt->m_callsign.c_str());
m_repeaters.erase(it); m_repeaters.erase(it);
delete itRpt;
network.setCount(m_repeaters.size()); network.setCount(m_repeaters.size());
break; break;
} }

Loading…
Cancel
Save