Get Windows working.

This commit is contained in:
Jonathan Naylor 2020-09-20 21:43:46 +01:00
parent e958203b11
commit e77fa3b3fa
9 changed files with 62 additions and 38 deletions

View File

@ -94,10 +94,12 @@ m_conf(file),
m_writer(NULL), m_writer(NULL),
m_gps(NULL) m_gps(NULL)
{ {
CUDPSocket::startup();
} }
CNXDNGateway::~CNXDNGateway() CNXDNGateway::~CNXDNGateway()
{ {
CUDPSocket::shutdown();
} }
void CNXDNGateway::run() void CNXDNGateway::run()

View File

@ -37,12 +37,6 @@ m_address_save(address),
m_port_save(port), m_port_save(port),
m_counter(0U) 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++) { for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = ""; m_address[i] = "";
m_port[i] = 0U; m_port[i] = 0U;
@ -56,12 +50,6 @@ m_address_save(),
m_port_save(port), m_port_save(port),
m_counter(0U) 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++) { for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = ""; m_address[i] = "";
m_port[i] = 0U; m_port[i] = 0U;
@ -72,6 +60,20 @@ m_counter(0U)
CUDPSocket::~CUDPSocket() 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) #if defined(_WIN32) || defined(_WIN64)
::WSACleanup(); ::WSACleanup();
#endif #endif

View File

@ -60,8 +60,12 @@ public:
void close(); void close();
void close(const unsigned int index); 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);
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); 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 match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);
static bool isNone(const sockaddr_storage& addr); static bool isNone(const sockaddr_storage& addr);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2018 by Jonathan Naylor G4KLX * Copyright (C) 2016,2018,2020 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -50,10 +50,12 @@ int main(int argc, char** argv)
CNXDNParrot::CNXDNParrot(unsigned int port) : CNXDNParrot::CNXDNParrot(unsigned int port) :
m_port(port) m_port(port)
{ {
CUDPSocket::startup();
} }
CNXDNParrot::~CNXDNParrot() CNXDNParrot::~CNXDNParrot()
{ {
CUDPSocket::shutdown();
} }
void CNXDNParrot::run() void CNXDNParrot::run()

View File

@ -37,12 +37,6 @@ m_address_save(address),
m_port_save(port), m_port_save(port),
m_counter(0U) 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++) { for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = ""; m_address[i] = "";
m_port[i] = 0U; m_port[i] = 0U;
@ -56,12 +50,6 @@ m_address_save(),
m_port_save(port), m_port_save(port),
m_counter(0U) 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++) { for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = ""; m_address[i] = "";
m_port[i] = 0U; m_port[i] = 0U;
@ -72,6 +60,20 @@ m_counter(0U)
CUDPSocket::~CUDPSocket() 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) #if defined(_WIN32) || defined(_WIN64)
::WSACleanup(); ::WSACleanup();
#endif #endif

View File

@ -32,7 +32,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#else #else
#include <WS2tcpip.h> #include <ws2tcpip.h>
#endif #endif
#if !defined(UDP_SOCKET_MAX) #if !defined(UDP_SOCKET_MAX)
@ -60,8 +60,12 @@ public:
void close(); void close();
void close(const unsigned int index); 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);
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); 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 match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);
static bool isNone(const sockaddr_storage& addr); static bool isNone(const sockaddr_storage& addr);

View File

@ -83,10 +83,12 @@ m_icomNetwork(NULL),
m_kenwoodNetwork(NULL), m_kenwoodNetwork(NULL),
m_repeaters() m_repeaters()
{ {
CUDPSocket::startup();
} }
CNXDNReflector::~CNXDNReflector() CNXDNReflector::~CNXDNReflector()
{ {
CUDPSocket::shutdown();
} }
void CNXDNReflector::run() void CNXDNReflector::run()

View File

@ -37,12 +37,6 @@ m_address_save(address),
m_port_save(port), m_port_save(port),
m_counter(0U) 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++) { for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = ""; m_address[i] = "";
m_port[i] = 0U; m_port[i] = 0U;
@ -56,12 +50,6 @@ m_address_save(),
m_port_save(port), m_port_save(port),
m_counter(0U) 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++) { for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = ""; m_address[i] = "";
m_port[i] = 0U; m_port[i] = 0U;
@ -72,6 +60,20 @@ m_counter(0U)
CUDPSocket::~CUDPSocket() 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) #if defined(_WIN32) || defined(_WIN64)
::WSACleanup(); ::WSACleanup();
#endif #endif

View File

@ -60,8 +60,12 @@ public:
void close(); void close();
void close(const unsigned int index); 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);
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); 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 match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);
static bool isNone(const sockaddr_storage& addr); static bool isNone(const sockaddr_storage& addr);