Merge pull request #8901 from sepalani/dns-async

IOS/Network: Make name resolution asynchronous
This commit is contained in:
JMC47 2021-08-29 05:12:13 -04:00 committed by GitHub
commit 006fc99e8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 2 deletions

View File

@ -64,6 +64,13 @@ enum SOResultCode : s32
NetIPTopDevice::NetIPTopDevice(Kernel& ios, const std::string& device_name) NetIPTopDevice::NetIPTopDevice(Kernel& ios, const std::string& device_name)
: Device(ios, device_name) : Device(ios, device_name)
{ {
m_work_queue.Reset([this](AsyncTask task) {
const IPCReply reply = task.handler();
{
std::lock_guard lg(m_async_reply_lock);
m_async_replies.emplace(AsyncReply{task.request, reply.return_value});
}
});
} }
void NetIPTopDevice::DoState(PointerWrap& p) void NetIPTopDevice::DoState(PointerWrap& p)
@ -319,7 +326,7 @@ std::optional<IPCReply> NetIPTopDevice::IOCtl(const IOCtlRequest& request)
case IOCTL_SO_POLL: case IOCTL_SO_POLL:
return HandlePollRequest(request); return HandlePollRequest(request);
case IOCTL_SO_GETHOSTBYNAME: case IOCTL_SO_GETHOSTBYNAME:
return HandleGetHostByNameRequest(request); return LaunchAsyncTask(&NetIPTopDevice::HandleGetHostByNameRequest, request);
case IOCTL_SO_ICMPCANCEL: case IOCTL_SO_ICMPCANCEL:
return HandleICMPCancelRequest(request); return HandleICMPCancelRequest(request);
default: default:
@ -341,7 +348,7 @@ std::optional<IPCReply> NetIPTopDevice::IOCtlV(const IOCtlVRequest& request)
case IOCTLV_SO_RECVFROM: case IOCTLV_SO_RECVFROM:
return HandleRecvFromRequest(request); return HandleRecvFromRequest(request);
case IOCTLV_SO_GETADDRINFO: case IOCTLV_SO_GETADDRINFO:
return HandleGetAddressInfoRequest(request); return LaunchAsyncTask(&NetIPTopDevice::HandleGetAddressInfoRequest, request);
case IOCTLV_SO_ICMPPING: case IOCTLV_SO_ICMPPING:
return HandleICMPPingRequest(request); return HandleICMPPingRequest(request);
default: default:
@ -354,6 +361,15 @@ std::optional<IPCReply> NetIPTopDevice::IOCtlV(const IOCtlVRequest& request)
void NetIPTopDevice::Update() void NetIPTopDevice::Update()
{ {
{
std::lock_guard lg(m_async_reply_lock);
while (!m_async_replies.empty())
{
const auto& reply = m_async_replies.front();
GetIOS()->EnqueueIPCReply(reply.request, reply.return_value);
m_async_replies.pop();
}
}
WiiSockMan::GetInstance().Update(); WiiSockMan::GetInstance().Update();
} }

View File

@ -3,10 +3,12 @@
#pragma once #pragma once
#include <queue>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/SocketContext.h" #include "Common/SocketContext.h"
#include "Common/WorkQueueThread.h"
#include "Core/IOS/Device.h" #include "Core/IOS/Device.h"
#ifdef _WIN32 #ifdef _WIN32
@ -73,6 +75,25 @@ public:
void Update() override; void Update() override;
private: private:
struct AsyncTask
{
IOS::HLE::Request request;
std::function<IPCReply()> handler;
};
struct AsyncReply
{
IOS::HLE::Request request;
s32 return_value;
};
template <typename Method, typename Request>
std::optional<IPCReply> LaunchAsyncTask(Method method, const Request& request)
{
m_work_queue.EmplaceItem(AsyncTask{request, std::bind(method, this, request)});
return std::nullopt;
}
IPCReply HandleInitInterfaceRequest(const IOCtlRequest& request); IPCReply HandleInitInterfaceRequest(const IOCtlRequest& request);
IPCReply HandleSocketRequest(const IOCtlRequest& request); IPCReply HandleSocketRequest(const IOCtlRequest& request);
IPCReply HandleICMPSocketRequest(const IOCtlRequest& request); IPCReply HandleICMPSocketRequest(const IOCtlRequest& request);
@ -99,5 +120,8 @@ private:
IPCReply HandleICMPPingRequest(const IOCtlVRequest& request); IPCReply HandleICMPPingRequest(const IOCtlVRequest& request);
Common::SocketContext m_socket_context; Common::SocketContext m_socket_context;
Common::WorkQueueThread<AsyncTask> m_work_queue;
std::mutex m_async_reply_lock;
std::queue<AsyncReply> m_async_replies;
}; };
} // namespace IOS::HLE } // namespace IOS::HLE