diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index e80b2cb786..6c3b6ae79b 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -1,6 +1,7 @@ set(SRCS BreakPoints.cpp CDUtils.cpp ColorUtil.cpp + ENetUtil.cpp FileSearch.cpp FileUtil.cpp GekkoDisassembler.cpp diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index ced0c431df..7b2c278cd1 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -51,6 +51,7 @@ + @@ -94,6 +95,7 @@ + @@ -146,4 +148,4 @@ - \ No newline at end of file + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index 8545274fc4..ffaf7d6be8 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -25,6 +25,7 @@ + @@ -78,6 +79,7 @@ + diff --git a/Source/Core/Common/ENetUtil.cpp b/Source/Core/Common/ENetUtil.cpp new file mode 100644 index 0000000000..7269893f90 --- /dev/null +++ b/Source/Core/Common/ENetUtil.cpp @@ -0,0 +1,28 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "ENetUtil.h" + +namespace ENetUtil +{ + +void WakeupThread(ENetHost* host) +{ + // Send ourselves a spurious message. This is hackier than it should be. + // comex reported this as https://github.com/lsalzman/enet/issues/23, so + // hopefully there will be a better way to do it in the future. + ENetAddress address; + if (host->address.port != 0) + address.port = host->address.port; + else + enet_socket_get_address(host->socket, &address); + address.host = 0x0100007f; // localhost + u8 byte = 0; + ENetBuffer buf; + buf.data = &byte; + buf.dataLength = 1; + enet_socket_send(host->socket, &address, &buf, 1); +} + +} diff --git a/Source/Core/Common/ENetUtil.h b/Source/Core/Common/ENetUtil.h new file mode 100644 index 0000000000..e9789673ad --- /dev/null +++ b/Source/Core/Common/ENetUtil.h @@ -0,0 +1,15 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. +// +#pragma once + +#include +#include "Common.h" + +namespace ENetUtil +{ + +void WakeupThread(ENetHost* host); + +} diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 2e792233fc..9aeaf3b8cf 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -485,25 +485,7 @@ void NetPlayClient::RunOnThread(std::function func) std::lock_guard lkq(m_crit.run_queue_write); m_run_queue.Push(func); } - WakeupThread(m_client); -} - -void NetPlayClient::WakeupThread(ENetHost* host) -{ - // Send ourselves a spurious message. This is hackier than it should be. - // comex reported this as https://github.com/lsalzman/enet/issues/23, so - // hopefully there will be a better way to do it in the future. - ENetAddress address; - if (host->address.port != 0) - address.port = host->address.port; - else - enet_socket_get_address(host->socket, &address); - address.host = 0x0100007f; // localhost - u8 byte = 0; - ENetBuffer buf; - buf.data = &byte; - buf.dataLength = 1; - enet_socket_send(host->socket, &address, &buf, 1); + ENetUtil::WakeupThread(m_client); } // called from ---NETPLAY--- thread diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 7b2e3e159a..441cc17fb3 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -9,6 +9,7 @@ #include #include #include "Common/CommonTypes.h" +#include "Common/ENetUtil.h" #include "Common/FifoQueue.h" #include "Common/Thread.h" #include "Common/Timer.h" @@ -48,7 +49,6 @@ class NetPlayClient : public TraversalClientClient public: void ThreadFunc(); void RunOnThread(std::function func); - void WakeupThread(ENetHost* host); NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, std::string centralServer, u16 centralPort); ~NetPlayClient(); diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 7b96b14846..2c01b270f2 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -454,25 +454,7 @@ void NetPlayServer::RunOnThread(std::function func) std::lock_guard lkq(m_crit.run_queue_write); m_run_queue.Push(func); } - WakeupThread(m_server); -} - -void NetPlayServer::WakeupThread(ENetHost* host) -{ - // Send ourselves a spurious message. This is hackier than it should be. - // comex reported this as https://github.com/lsalzman/enet/issues/23, so - // hopefully there will be a better way to do it in the future. - ENetAddress address; - if (host->address.port != 0) - address.port = host->address.port; - else - enet_socket_get_address(host->socket, &address); - address.host = 0x0100007f; // localhost - u8 byte = 0; - ENetBuffer buf; - buf.data = &byte; - buf.dataLength = 1; - enet_socket_send(host->socket, &address, &buf, 1); + ENetUtil::WakeupThread(m_server); } // called from ---NETPLAY--- thread diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 21f7ea9ede..6c53b537ad 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -9,6 +9,7 @@ #include #include #include +#include "Common/ENetUtil.h" #include "Common/Thread.h" #include "Common/Timer.h" #include "Common/TraversalClient.h" @@ -21,7 +22,6 @@ class NetPlayServer : public TraversalClientClient public: void ThreadFunc(); void RunOnThread(std::function func); - void WakeupThread(ENetHost* host); NetPlayServer(const u16 port, bool traversal, std::string centralServer, u16 centralPort); ~NetPlayServer();