From b2ba6710712282305d2827624e6eab38316cce42 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 20 Sep 2020 14:07:42 +0100 Subject: [PATCH 1/2] Fix Windows compilation. --- LCDproc.cpp | 2 +- UDPSocket.h | 1 - Version.h | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/LCDproc.cpp b/LCDproc.cpp index 5f072e9..19ac15e 100644 --- a/LCDproc.cpp +++ b/LCDproc.cpp @@ -72,7 +72,7 @@ #include #include #else -#include +#include #endif #define BUFFER_MAX_LEN 128 diff --git a/UDPSocket.h b/UDPSocket.h index b22eefc..3f5585b 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -32,7 +32,6 @@ #include #include #else -#include #include #endif diff --git a/Version.h b/Version.h index a988871..3e08686 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20200906"; +const char* VERSION = "20200920"; #endif From 5eabb930788509aa8b3e7062457ffa7c6081b988 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 20 Sep 2020 21:31:32 +0100 Subject: [PATCH 2/2] Fix Windows execution. --- MMDVMHost.cpp | 2 ++ RemoteCommand.cpp | 4 ++++ UDPSocket.cpp | 26 ++++++++++++++------------ UDPSocket.h | 4 ++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 1061e7e..bfede16 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -164,10 +164,12 @@ m_lockFileName(), m_remoteControl(NULL), m_fixedMode(false) { + CUDPSocket::startup(); } CMMDVMHost::~CMMDVMHost() { + CUDPSocket::shutdown(); } int CMMDVMHost::run() diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index addc0c6..04322ae 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -51,12 +51,16 @@ int main(int argc, char** argv) CRemoteCommand::CRemoteCommand(unsigned int port) : m_port(port) { + CUDPSocket::startup(); + ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U); } CRemoteCommand::~CRemoteCommand() { ::LogFinalise(); + + CUDPSocket::shutdown(); } int CRemoteCommand::send(const std::string& command) diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 382925f..3f6192a 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -37,12 +37,6 @@ m_address_save(address), m_port_save(port), m_counter(0U) { -#if defined(_WIN32) || defined(_WIN64) - WSAData data; - int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); - if (wsaRet != 0) - LogError("Error from WSAStartup"); -#endif for (int i = 0; i < UDP_SOCKET_MAX; i++) { m_address[i] = ""; m_port[i] = 0U; @@ -56,12 +50,6 @@ m_address_save(), m_port_save(port), m_counter(0U) { -#if defined(_WIN32) || defined(_WIN64) - WSAData data; - int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); - if (wsaRet != 0) - LogError("Error from WSAStartup"); -#endif for (int i = 0; i < UDP_SOCKET_MAX; i++) { m_address[i] = ""; m_port[i] = 0U; @@ -72,6 +60,20 @@ m_counter(0U) CUDPSocket::~CUDPSocket() { +} + +void CUDPSocket::startup() +{ +#if defined(_WIN32) || defined(_WIN64) + WSAData data; + int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); + if (wsaRet != 0) + LogError("Error from WSAStartup"); +#endif +} + +void CUDPSocket::shutdown() +{ #if defined(_WIN32) || defined(_WIN64) ::WSACleanup(); #endif diff --git a/UDPSocket.h b/UDPSocket.h index 3f5585b..6e3846c 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -60,8 +60,12 @@ public: void close(); void close(const unsigned int index); + static void startup(); + static void shutdown(); + static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length); static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); + static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT); static bool isNone(const sockaddr_storage& addr);