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
CDUtils.cpp
ColorUtil.cpp
ENetUtil.cpp
FileSearch.cpp
FileUtil.cpp
GekkoDisassembler.cpp

View file

@ -51,6 +51,7 @@
<ClInclude Include="CommonTypes.h" />
<ClInclude Include="CPUDetect.h" />
<ClInclude Include="DebugInterface.h" />
<ClInclude Include="ENetUtil.h" />
<ClInclude Include="Event.h" />
<ClInclude Include="FifoQueue.h" />
<ClInclude Include="FileSearch.h" />
@ -94,6 +95,7 @@
<ClCompile Include="BreakPoints.cpp" />
<ClCompile Include="CDUtils.cpp" />
<ClCompile Include="ColorUtil.cpp" />
<ClCompile Include="ENetUtil.cpp" />
<ClCompile Include="FileSearch.cpp" />
<ClCompile Include="FileUtil.cpp" />
<ClCompile Include="GekkoDisassembler.cpp" />
@ -146,4 +148,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View file

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

View file

@ -9,6 +9,7 @@
#include <sstream>
#include <SFML/Network/Packet.hpp>
#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<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();

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

View file

@ -9,6 +9,7 @@
#include <sstream>
#include <unordered_set>
#include <SFML/Network/Packet.hpp>
#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<void()> func);
void WakeupThread(ENetHost* host);
NetPlayServer(const u16 port, bool traversal, std::string centralServer, u16 centralPort);
~NetPlayServer();