diff --git a/DMRGateway.cpp b/DMRGateway.cpp index 8f7c759..badb05b 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -77,7 +77,7 @@ static CDMRGateway* gateway = NULL; const char* HEADER1 = "This software is for use on amateur radio networks only,"; const char* HEADER2 = "it is to be used for educational purposes only. Its use on"; const char* HEADER3 = "commercial networks is strictly prohibited."; -const char* HEADER4 = "Copyright(C) 2017-2023 by Jonathan Naylor, G4KLX and others"; +const char* HEADER4 = "Copyright(C) 2017-2024 by Jonathan Naylor, G4KLX and others"; int main(int argc, char** argv) { @@ -109,6 +109,7 @@ int main(int argc, char** argv) do { m_killed = false; m_signal = 0; + m_killed = false; // restart, don't exit, if looping from SIGHUP (1) gateway = new CDMRGateway(std::string(iniFile)); ret = gateway->run(); diff --git a/DMRGateway.vcxproj b/DMRGateway.vcxproj index 9276e93..db7d4ec 100644 --- a/DMRGateway.vcxproj +++ b/DMRGateway.vcxproj @@ -94,6 +94,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -109,10 +112,11 @@ ws2_32.lib;%(AdditionalDependencies) - "$(ProjectDir)prebuild.cmd" $(ProjectDir) + prebuild.cmd - prebuild.cmd generates GitVersion.h from git refs heads master + + @@ -132,6 +136,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -150,6 +157,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 6981e29..c28c039 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -36,7 +36,11 @@ CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) : m_localAddress(address), m_localPort(port), +#if defined(_WIN32) || defined(_WIN64) +m_fd(INVALID_SOCKET), +#else m_fd(-1), +#endif m_af(AF_UNSPEC) { } @@ -44,7 +48,11 @@ m_af(AF_UNSPEC) CUDPSocket::CUDPSocket(unsigned short port) : m_localAddress(), m_localPort(port), +#if defined(_WIN32) || defined(_WIN64) +m_fd(INVALID_SOCKET), +#else m_fd(-1), +#endif m_af(AF_UNSPEC) { } @@ -97,7 +105,9 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockadd return err; } - ::memcpy(&addr, res->ai_addr, address_length = res->ai_addrlen); + address_length = (unsigned int)res->ai_addrlen; + + ::memcpy(&addr, res->ai_addr, address_length); ::freeaddrinfo(res); @@ -160,7 +170,11 @@ bool CUDPSocket::open(const sockaddr_storage& address) bool CUDPSocket::open() { +#if defined(_WIN32) || defined(_WIN64) + assert(m_fd == INVALID_SOCKET); +#else assert(m_fd == -1); +#endif sockaddr_storage addr; unsigned int addrlen; @@ -221,7 +235,14 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag { assert(buffer != NULL); assert(length > 0U); - assert(m_fd >= 0); + +#if defined(_WIN32) || defined(_WIN64) + if (m_fd == INVALID_SOCKET) + return 0; +#else + if (m_fd == -1) + return 0; +#endif // Check that the readfrom() won't block struct pollfd pfd; @@ -282,7 +303,11 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s { assert(buffer != NULL); assert(length > 0U); +#if defined(_WIN32) || defined(_WIN64) + assert(m_fd != INVALID_SOCKET); +#else assert(m_fd >= 0); +#endif bool result = false; @@ -313,13 +338,16 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s void CUDPSocket::close() { - if (m_fd >= 0) { #if defined(_WIN32) || defined(_WIN64) + if (m_fd != INVALID_SOCKET) { ::closesocket(m_fd); + m_fd = INVALID_SOCKET; + } #else + if (m_fd >= 0) { ::close(m_fd); -#endif m_fd = -1; } +#endif } diff --git a/UDPSocket.h b/UDPSocket.h index 28e350c..75228a3 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -69,10 +69,11 @@ private: unsigned short m_localPort; #if defined(_WIN32) || defined(_WIN64) SOCKET m_fd; + int m_af; #else int m_fd; -#endif sa_family_t m_af; +#endif }; #endif