Skip to content

Commit 5eabb93

Browse files
committed
Fix Windows execution.
1 parent b2ba671 commit 5eabb93

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

MMDVMHost.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ m_lockFileName(),
164164
m_remoteControl(NULL),
165165
m_fixedMode(false)
166166
{
167+
CUDPSocket::startup();
167168
}
168169

169170
CMMDVMHost::~CMMDVMHost()
170171
{
172+
CUDPSocket::shutdown();
171173
}
172174

173175
int CMMDVMHost::run()

RemoteCommand.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ int main(int argc, char** argv)
5151
CRemoteCommand::CRemoteCommand(unsigned int port) :
5252
m_port(port)
5353
{
54+
CUDPSocket::startup();
55+
5456
::LogInitialise(false, ".", "RemoteCommand", 2U, 2U);
5557
}
5658

5759
CRemoteCommand::~CRemoteCommand()
5860
{
5961
::LogFinalise();
62+
63+
CUDPSocket::shutdown();
6064
}
6165

6266
int CRemoteCommand::send(const std::string& command)

UDPSocket.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ m_address_save(address),
3737
m_port_save(port),
3838
m_counter(0U)
3939
{
40-
#if defined(_WIN32) || defined(_WIN64)
41-
WSAData data;
42-
int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data);
43-
if (wsaRet != 0)
44-
LogError("Error from WSAStartup");
45-
#endif
4640
for (int i = 0; i < UDP_SOCKET_MAX; i++) {
4741
m_address[i] = "";
4842
m_port[i] = 0U;
@@ -56,12 +50,6 @@ m_address_save(),
5650
m_port_save(port),
5751
m_counter(0U)
5852
{
59-
#if defined(_WIN32) || defined(_WIN64)
60-
WSAData data;
61-
int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data);
62-
if (wsaRet != 0)
63-
LogError("Error from WSAStartup");
64-
#endif
6553
for (int i = 0; i < UDP_SOCKET_MAX; i++) {
6654
m_address[i] = "";
6755
m_port[i] = 0U;
@@ -72,6 +60,20 @@ m_counter(0U)
7260

7361
CUDPSocket::~CUDPSocket()
7462
{
63+
}
64+
65+
void CUDPSocket::startup()
66+
{
67+
#if defined(_WIN32) || defined(_WIN64)
68+
WSAData data;
69+
int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data);
70+
if (wsaRet != 0)
71+
LogError("Error from WSAStartup");
72+
#endif
73+
}
74+
75+
void CUDPSocket::shutdown()
76+
{
7577
#if defined(_WIN32) || defined(_WIN64)
7678
::WSACleanup();
7779
#endif

UDPSocket.h

+4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ class CUDPSocket {
6060
void close();
6161
void close(const unsigned int index);
6262

63+
static void startup();
64+
static void shutdown();
65+
6366
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length);
6467
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints);
68+
6569
static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);
6670

6771
static bool isNone(const sockaddr_storage& addr);

0 commit comments

Comments
 (0)