diff --git a/DMRDirectNetwork.cpp b/DMRDirectNetwork.cpp index a378f7a..a27a646 100644 --- a/DMRDirectNetwork.cpp +++ b/DMRDirectNetwork.cpp @@ -321,11 +321,11 @@ bool CDMRDirectNetwork::isConnected() const return (m_status == RUNNING); } -void CDMRDirectNetwork::close() +void CDMRDirectNetwork::close(bool sayGoodbye) { LogMessage("Closing DMR Network"); - if (m_status == RUNNING) { + if (sayGoodbye && (m_status == RUNNING)) { unsigned char buffer[9U]; ::memcpy(buffer + 0U, "RPTCL", 5U); ::memcpy(buffer + 5U, m_id, 4U); @@ -377,7 +377,7 @@ void CDMRDirectNetwork::clock(unsigned int ms) int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, addrlen); if (length < 0) { LogError("DMR, Socket has failed, retrying connection to the master"); - close(); + close(false); open(); return; } @@ -408,7 +408,7 @@ void CDMRDirectNetwork::clock(unsigned int ms) the Network sometimes times out and reaches here. We want it to reconnect so... */ LogError("DMR, Login to the master has failed, retrying network ..."); - close(); + close(false); open(); return; } @@ -452,7 +452,7 @@ void CDMRDirectNetwork::clock(unsigned int ms) } } else if (::memcmp(m_buffer, "MSTCL", 5U) == 0) { LogError("DMR, Master is closing down"); - close(); + close(false); open(); } else if (::memcmp(m_buffer, "MSTPONG", 7U) == 0) { m_timeoutTimer.start(); @@ -466,7 +466,7 @@ void CDMRDirectNetwork::clock(unsigned int ms) m_timeoutTimer.clock(ms); if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) { LogError("DMR, Connection to the master has timed out, retrying connection"); - close(); + close(false); open(); } } @@ -635,7 +635,7 @@ bool CDMRDirectNetwork::write(const unsigned char* data, unsigned int length) bool ret = m_socket.write(data, length, m_addr, m_addrLen); if (!ret) { LogError("DMR, Socket has failed when writing data to the master, retrying connection"); - m_socket.close(); + close(false); open(); return false; } diff --git a/DMRDirectNetwork.h b/DMRDirectNetwork.h index f6e0834..6df82cc 100644 --- a/DMRDirectNetwork.h +++ b/DMRDirectNetwork.h @@ -57,7 +57,7 @@ public: virtual bool isConnected() const; - virtual void close(); + virtual void close(bool sayGoodbye); private: std::string m_address; diff --git a/DMRGatewayNetwork.cpp b/DMRGatewayNetwork.cpp index dd86e76..f6dfe47 100644 --- a/DMRGatewayNetwork.cpp +++ b/DMRGatewayNetwork.cpp @@ -289,10 +289,10 @@ bool CDMRGatewayNetwork::writeTalkerAlias(unsigned int id, unsigned char type, c bool CDMRGatewayNetwork::isConnected() const { - return (m_enabled && (m_addrLen != 0)); + return (m_addrLen != 0); } -void CDMRGatewayNetwork::close() +void CDMRGatewayNetwork::close(bool sayGoodbye) { LogMessage("DMR, Closing DMR Network"); diff --git a/DMRGatewayNetwork.h b/DMRGatewayNetwork.h index bc00385..7bca94f 100644 --- a/DMRGatewayNetwork.h +++ b/DMRGatewayNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020,2021 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 @@ -58,7 +58,7 @@ public: virtual bool isConnected() const; - virtual void close(); + virtual void close(bool sayGoodbye); private: std::string m_addressStr; diff --git a/DMRNetwork.h b/DMRNetwork.h index 4a3c4d7..006e097 100644 --- a/DMRNetwork.h +++ b/DMRNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020,2021 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 @@ -50,7 +50,7 @@ public: virtual bool isConnected() const = 0; - virtual void close() = 0; + virtual void close(bool sayGoodbye) = 0; private: }; diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index 2de9051..eae4f8f 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -316,7 +316,7 @@ void CDStarNetwork::reset() bool CDStarNetwork::isConnected() const { - return (m_enabled && (m_addrLen != 0)); + return (m_addrLen != 0); } void CDStarNetwork::close() diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index b21870a..966bf76 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -1260,7 +1260,7 @@ int CMMDVMHost::run() } if (m_dmrNetwork != NULL) { - m_dmrNetwork->close(); + m_dmrNetwork->close(true); delete m_dmrNetwork; } diff --git a/NXDNIcomNetwork.cpp b/NXDNIcomNetwork.cpp index 5f20b37..730f445 100644 --- a/NXDNIcomNetwork.cpp +++ b/NXDNIcomNetwork.cpp @@ -155,7 +155,7 @@ void CNXDNIcomNetwork::reset() bool CNXDNIcomNetwork::isConnected() const { - return (m_enabled && (m_addrLen != 0)); + return (m_addrLen != 0); } void CNXDNIcomNetwork::close() diff --git a/NXDNKenwoodNetwork.cpp b/NXDNKenwoodNetwork.cpp index 3866133..bed3316 100644 --- a/NXDNKenwoodNetwork.cpp +++ b/NXDNKenwoodNetwork.cpp @@ -837,7 +837,7 @@ void CNXDNKenwoodNetwork::reset() bool CNXDNKenwoodNetwork::isConnected() const { - return (m_enabled && (m_rtcpAddrLen != 0U) && (m_rtpAddrLen != 0U)); + return ((m_rtcpAddrLen != 0U) && (m_rtpAddrLen != 0U)); } void CNXDNKenwoodNetwork::close() diff --git a/P25Network.cpp b/P25Network.cpp index 2734373..77a9a7d 100644 --- a/P25Network.cpp +++ b/P25Network.cpp @@ -426,7 +426,7 @@ unsigned int CP25Network::read(unsigned char* data, unsigned int length) bool CP25Network::isConnected() const { - return (m_enabled && (m_addrLen != 0)); + return (m_addrLen != 0); } void CP25Network::close() diff --git a/UDPSocket.cpp b/UDPSocket.cpp index ad8a0eb..7b819fe 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -188,6 +188,8 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std return false; } + close(index); + int fd = ::socket(addr.ss_family, SOCK_DGRAM, 0); if (fd < 0) { #if defined(_WIN32) || defined(_WIN64) @@ -344,13 +346,13 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s void CUDPSocket::close() { - for (int i = 0; i < UDP_SOCKET_MAX; i++) - close(m_fd[i]); + for (unsigned int i = 0; i < UDP_SOCKET_MAX; i++) + close(i); } void CUDPSocket::close(const unsigned int index) { - if (m_fd[index] >= 0) { + if ((index < UDP_SOCKET_MAX) && (m_fd[index] >= 0)) { #if defined(_WIN32) || defined(_WIN64) ::closesocket(m_fd[index]); #else diff --git a/Version.h b/Version.h index 9aea486..486d545 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20210407"; +const char* VERSION = "20210408"; #endif