IOS/Network: Make name resolution asynchronous

This commit is contained in:
Sepalani 2020-06-26 01:05:04 +04:00
parent c77a5f7e32
commit 0553aeb0e0
2 changed files with 42 additions and 2 deletions

View File

@ -65,6 +65,13 @@ enum SOResultCode : s32
NetIPTopDevice::NetIPTopDevice(Kernel& ios, const std::string& 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)
@ -320,7 +327,7 @@ std::optional<IPCReply> NetIPTopDevice::IOCtl(const IOCtlRequest& request)
case IOCTL_SO_POLL:
return HandlePollRequest(request);
case IOCTL_SO_GETHOSTBYNAME:
return HandleGetHostByNameRequest(request);
return LaunchAsyncTask(&NetIPTopDevice::HandleGetHostByNameRequest, request);
case IOCTL_SO_ICMPCANCEL:
return HandleICMPCancelRequest(request);
default:
@ -342,7 +349,7 @@ std::optional<IPCReply> NetIPTopDevice::IOCtlV(const IOCtlVRequest& request)
case IOCTLV_SO_RECVFROM:
return HandleRecvFromRequest(request);
case IOCTLV_SO_GETADDRINFO:
return HandleGetAddressInfoRequest(request);
return LaunchAsyncTask(&NetIPTopDevice::HandleGetAddressInfoRequest, request);
case IOCTLV_SO_ICMPPING:
return HandleICMPPingRequest(request);
default:
@ -355,6 +362,15 @@ std::optional<IPCReply> NetIPTopDevice::IOCtlV(const IOCtlVRequest& request)
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();
}

View File

@ -4,10 +4,12 @@
#pragma once
#include <queue>
#include <string>
#include "Common/CommonTypes.h"
#include "Common/SocketContext.h"
#include "Common/WorkQueueThread.h"
#include "Core/IOS/Device.h"
#ifdef _WIN32
@ -74,6 +76,25 @@ public:
void Update() override;
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 HandleSocketRequest(const IOCtlRequest& request);
IPCReply HandleICMPSocketRequest(const IOCtlRequest& request);
@ -100,5 +121,8 @@ private:
IPCReply HandleICMPPingRequest(const IOCtlVRequest& request);
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