NetPlay: add a Common/ENetUtil namespace

Move WakeupThread in it
This commit is contained in:
mathieui 2015-03-09 18:37:02 +01:00
parent 603fe25349
commit 44d7207a1c
9 changed files with 53 additions and 41 deletions

View File

@ -1,6 +1,7 @@
set(SRCS BreakPoints.cpp set(SRCS BreakPoints.cpp
CDUtils.cpp CDUtils.cpp
ColorUtil.cpp ColorUtil.cpp
ENetUtil.cpp
FileSearch.cpp FileSearch.cpp
FileUtil.cpp FileUtil.cpp
GekkoDisassembler.cpp GekkoDisassembler.cpp

View File

@ -51,6 +51,7 @@
<ClInclude Include="CommonTypes.h" /> <ClInclude Include="CommonTypes.h" />
<ClInclude Include="CPUDetect.h" /> <ClInclude Include="CPUDetect.h" />
<ClInclude Include="DebugInterface.h" /> <ClInclude Include="DebugInterface.h" />
<ClInclude Include="ENetUtil.h" />
<ClInclude Include="Event.h" /> <ClInclude Include="Event.h" />
<ClInclude Include="FifoQueue.h" /> <ClInclude Include="FifoQueue.h" />
<ClInclude Include="FileSearch.h" /> <ClInclude Include="FileSearch.h" />
@ -94,6 +95,7 @@
<ClCompile Include="BreakPoints.cpp" /> <ClCompile Include="BreakPoints.cpp" />
<ClCompile Include="CDUtils.cpp" /> <ClCompile Include="CDUtils.cpp" />
<ClCompile Include="ColorUtil.cpp" /> <ClCompile Include="ColorUtil.cpp" />
<ClCompile Include="ENetUtil.cpp" />
<ClCompile Include="FileSearch.cpp" /> <ClCompile Include="FileSearch.cpp" />
<ClCompile Include="FileUtil.cpp" /> <ClCompile Include="FileUtil.cpp" />
<ClCompile Include="GekkoDisassembler.cpp" /> <ClCompile Include="GekkoDisassembler.cpp" />

View File

@ -25,6 +25,7 @@
<ClInclude Include="CommonTypes.h" /> <ClInclude Include="CommonTypes.h" />
<ClInclude Include="CPUDetect.h" /> <ClInclude Include="CPUDetect.h" />
<ClInclude Include="DebugInterface.h" /> <ClInclude Include="DebugInterface.h" />
<ClInclude Include="ENetUtil.h" />
<ClInclude Include="FifoQueue.h" /> <ClInclude Include="FifoQueue.h" />
<ClInclude Include="FileSearch.h" /> <ClInclude Include="FileSearch.h" />
<ClInclude Include="FileUtil.h" /> <ClInclude Include="FileUtil.h" />
@ -78,6 +79,7 @@
<ClCompile Include="BreakPoints.cpp" /> <ClCompile Include="BreakPoints.cpp" />
<ClCompile Include="CDUtils.cpp" /> <ClCompile Include="CDUtils.cpp" />
<ClCompile Include="ColorUtil.cpp" /> <ClCompile Include="ColorUtil.cpp" />
<ClCompile Include="ENetUtil.cpp" />
<ClCompile Include="FileSearch.cpp" /> <ClCompile Include="FileSearch.cpp" />
<ClCompile Include="FileUtil.cpp" /> <ClCompile Include="FileUtil.cpp" />
<ClCompile Include="Hash.cpp" /> <ClCompile Include="Hash.cpp" />

View File

@ -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);
}
}

View File

@ -0,0 +1,15 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
//
#pragma once
#include <enet/enet.h>
#include "Common.h"
namespace ENetUtil
{
void WakeupThread(ENetHost* host);
}

View File

@ -485,25 +485,7 @@ void NetPlayClient::RunOnThread(std::function<void()> func)
std::lock_guard<std::recursive_mutex> lkq(m_crit.run_queue_write); std::lock_guard<std::recursive_mutex> lkq(m_crit.run_queue_write);
m_run_queue.Push(func); m_run_queue.Push(func);
} }
WakeupThread(m_client); ENetUtil::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);
} }
// called from ---NETPLAY--- thread // called from ---NETPLAY--- thread

View File

@ -9,6 +9,7 @@
#include <sstream> #include <sstream>
#include <SFML/Network/Packet.hpp> #include <SFML/Network/Packet.hpp>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/ENetUtil.h"
#include "Common/FifoQueue.h" #include "Common/FifoQueue.h"
#include "Common/Thread.h" #include "Common/Thread.h"
#include "Common/Timer.h" #include "Common/Timer.h"
@ -48,7 +49,6 @@ class NetPlayClient : public TraversalClientClient
public: public:
void ThreadFunc(); void ThreadFunc();
void RunOnThread(std::function<void()> func); void RunOnThread(std::function<void()> 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(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, std::string centralServer, u16 centralPort);
~NetPlayClient(); ~NetPlayClient();

View File

@ -454,25 +454,7 @@ void NetPlayServer::RunOnThread(std::function<void()> func)
std::lock_guard<std::recursive_mutex> lkq(m_crit.run_queue_write); std::lock_guard<std::recursive_mutex> lkq(m_crit.run_queue_write);
m_run_queue.Push(func); m_run_queue.Push(func);
} }
WakeupThread(m_server); ENetUtil::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);
} }
// called from ---NETPLAY--- thread // called from ---NETPLAY--- thread

View File

@ -9,6 +9,7 @@
#include <sstream> #include <sstream>
#include <unordered_set> #include <unordered_set>
#include <SFML/Network/Packet.hpp> #include <SFML/Network/Packet.hpp>
#include "Common/ENetUtil.h"
#include "Common/Thread.h" #include "Common/Thread.h"
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Common/TraversalClient.h" #include "Common/TraversalClient.h"
@ -21,7 +22,6 @@ class NetPlayServer : public TraversalClientClient
public: public:
void ThreadFunc(); void ThreadFunc();
void RunOnThread(std::function<void()> func); void RunOnThread(std::function<void()> func);
void WakeupThread(ENetHost* host);
NetPlayServer(const u16 port, bool traversal, std::string centralServer, u16 centralPort); NetPlayServer(const u16 port, bool traversal, std::string centralServer, u16 centralPort);
~NetPlayServer(); ~NetPlayServer();