summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/core.cpp13
-rw-r--r--src/core/cpu_manager.cpp8
-rw-r--r--src/core/crypto/aes_util.cpp2
-rw-r--r--src/core/hle/kernel/k_scheduler.cpp17
-rw-r--r--src/core/hle/kernel/k_thread.cpp50
-rw-r--r--src/core/hle/kernel/k_thread.h24
-rw-r--r--src/core/hle/kernel/kernel.cpp11
-rw-r--r--src/core/hle/kernel/process.cpp5
-rw-r--r--src/core/hle/kernel/svc.cpp5
-rw-r--r--src/core/network/network.cpp173
-rw-r--r--src/core/network/network.h6
11 files changed, 157 insertions, 157 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index de6305e2a..305f56ff1 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -299,28 +299,17 @@ struct System::Impl {
gpu_core->WaitIdle();
}
- // Shutdown emulation session
services.reset();
service_manager.reset();
cheat_engine.reset();
telemetry_session.reset();
-
- // Close all CPU/threading state
cpu_manager.Shutdown();
-
- // Release the Time Manager's resources
time_manager.Shutdown();
-
- // Shutdown kernel and core timing
core_timing.Shutdown();
- kernel.Shutdown();
-
- // Close app loader
app_loader.reset();
gpu_core.reset();
perf_stats.reset();
-
- // Clear all applets
+ kernel.Shutdown();
applet_manager.ClearAll();
LOG_DEBUG(Core, "Shutdown OK");
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index 8f04fb8f5..bdb374792 100644
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -148,7 +148,7 @@ void CpuManager::MultiCoreRunSuspendThread() {
auto core = kernel.GetCurrentHostThreadID();
auto& scheduler = *kernel.CurrentScheduler();
Kernel::KThread* current_thread = scheduler.GetCurrentThread();
- Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[core].host_context);
+ Common::Fiber::YieldTo(current_thread->GetHostContext(), *core_data[core].host_context);
ASSERT(scheduler.ContextSwitchPending());
ASSERT(core == kernel.GetCurrentHostThreadID());
scheduler.RescheduleCurrentCore();
@@ -245,7 +245,7 @@ void CpuManager::SingleCoreRunSuspendThread() {
auto core = kernel.GetCurrentHostThreadID();
auto& scheduler = *kernel.CurrentScheduler();
Kernel::KThread* current_thread = scheduler.GetCurrentThread();
- Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[0].host_context);
+ Common::Fiber::YieldTo(current_thread->GetHostContext(), *core_data[0].host_context);
ASSERT(scheduler.ContextSwitchPending());
ASSERT(core == kernel.GetCurrentHostThreadID());
scheduler.RescheduleCurrentCore();
@@ -271,7 +271,7 @@ void CpuManager::PreemptSingleCore(bool from_running_enviroment) {
scheduler.Unload(scheduler.GetCurrentThread());
auto& next_scheduler = kernel.Scheduler(current_core);
- Common::Fiber::YieldTo(current_thread->GetHostContext(), next_scheduler.ControlContext());
+ Common::Fiber::YieldTo(current_thread->GetHostContext(), *next_scheduler.ControlContext());
}
// May have changed scheduler
@@ -363,7 +363,7 @@ void CpuManager::RunThread(std::size_t core) {
auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread();
data.is_running = true;
- Common::Fiber::YieldTo(data.host_context, current_thread->GetHostContext());
+ Common::Fiber::YieldTo(data.host_context, *current_thread->GetHostContext());
data.is_running = false;
data.is_paused = true;
data.exit_barrier->Wait();
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp
index 6a9734812..cb7506241 100644
--- a/src/core/crypto/aes_util.cpp
+++ b/src/core/crypto/aes_util.cpp
@@ -105,8 +105,6 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, std::size_t size, u8* des
}
}
}
-
- mbedtls_cipher_finish(context, nullptr, nullptr);
}
template <typename Key, std::size_t KeySize>
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp
index bb5f43b53..e7de48476 100644
--- a/src/core/hle/kernel/k_scheduler.cpp
+++ b/src/core/hle/kernel/k_scheduler.cpp
@@ -734,7 +734,7 @@ void KScheduler::ScheduleImpl() {
}
guard.unlock();
- Common::Fiber::YieldTo(*old_context, switch_fiber);
+ Common::Fiber::YieldTo(*old_context, *switch_fiber);
/// When a thread wakes up, the scheduler may have changed to other in another core.
auto& next_scheduler = *system.Kernel().CurrentScheduler();
next_scheduler.SwitchContextStep2();
@@ -769,13 +769,8 @@ void KScheduler::SwitchToCurrent() {
break;
}
}
- std::shared_ptr<Common::Fiber>* next_context;
- if (next_thread != nullptr) {
- next_context = &next_thread->GetHostContext();
- } else {
- next_context = &idle_thread->GetHostContext();
- }
- Common::Fiber::YieldTo(switch_fiber, *next_context);
+ auto thread = next_thread ? next_thread : idle_thread;
+ Common::Fiber::YieldTo(switch_fiber, *thread->GetHostContext());
} while (!is_switch_pending());
}
}
@@ -800,9 +795,9 @@ void KScheduler::Initialize() {
std::string name = "Idle Thread Id:" + std::to_string(core_id);
std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc();
void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
- auto thread_res = KThread::Create(system, ThreadType::Main, name, 0,
- KThread::IdleThreadPriority, 0, static_cast<u32>(core_id), 0,
- nullptr, std::move(init_func), init_func_parameter);
+ auto thread_res = KThread::CreateThread(
+ system, ThreadType::Main, name, 0, KThread::IdleThreadPriority, 0,
+ static_cast<u32>(core_id), 0, nullptr, std::move(init_func), init_func_parameter);
idle_thread = thread_res.Unwrap().get();
}
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 1661afbd9..e0f53287c 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -995,22 +995,11 @@ std::shared_ptr<Common::Fiber>& KThread::GetHostContext() {
return host_context;
}
-ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, ThreadType type_flags,
- std::string name, VAddr entry_point,
- u32 priority, u64 arg, s32 processor_id,
- VAddr stack_top, Process* owner_process) {
- std::function<void(void*)> init_func = Core::CpuManager::GetGuestThreadStartFunc();
- void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
- return Create(system, type_flags, name, entry_point, priority, arg, processor_id, stack_top,
- owner_process, std::move(init_func), init_func_parameter);
-}
-
-ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, ThreadType type_flags,
- std::string name, VAddr entry_point,
- u32 priority, u64 arg, s32 processor_id,
- VAddr stack_top, Process* owner_process,
- std::function<void(void*)>&& thread_start_func,
- void* thread_start_parameter) {
+ResultVal<std::shared_ptr<KThread>> KThread::CreateThread(Core::System& system,
+ ThreadType type_flags, std::string name,
+ VAddr entry_point, u32 priority, u64 arg,
+ s32 processor_id, VAddr stack_top,
+ Process* owner_process) {
auto& kernel = system.Kernel();
std::shared_ptr<KThread> thread = std::make_shared<KThread>(kernel);
@@ -1027,12 +1016,35 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread
auto& scheduler = kernel.GlobalSchedulerContext();
scheduler.AddThread(thread);
- thread->host_context =
- std::make_shared<Common::Fiber>(std::move(thread_start_func), thread_start_parameter);
-
return MakeResult<std::shared_ptr<KThread>>(std::move(thread));
}
+ResultVal<std::shared_ptr<KThread>> KThread::CreateThread(
+ Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point, u32 priority,
+ u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process,
+ std::function<void(void*)>&& thread_start_func, void* thread_start_parameter) {
+ auto thread_result = CreateThread(system, type_flags, name, entry_point, priority, arg,
+ processor_id, stack_top, owner_process);
+
+ if (thread_result.Succeeded()) {
+ (*thread_result)->host_context =
+ std::make_shared<Common::Fiber>(std::move(thread_start_func), thread_start_parameter);
+ }
+
+ return thread_result;
+}
+
+ResultVal<std::shared_ptr<KThread>> KThread::CreateUserThread(
+ Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point, u32 priority,
+ u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process) {
+ std::function<void(void*)> init_func = Core::CpuManager::GetGuestThreadStartFunc();
+
+ void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
+
+ return CreateThread(system, type_flags, name, entry_point, priority, arg, processor_id,
+ stack_top, owner_process, std::move(init_func), init_func_parameter);
+}
+
KThread* GetCurrentThreadPointer(KernelCore& kernel) {
return kernel.GetCurrentEmuThread();
}
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index c8ac656a4..1c19b23dc 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -116,7 +116,7 @@ public:
using WaiterList = boost::intrusive::list<KThread>;
/**
- * Creates and returns a new thread. The new thread is immediately scheduled
+ * Creates and returns a new thread.
* @param system The instance of the whole system
* @param name The friendly name desired for the thread
* @param entry_point The address at which the thread should start execution
@@ -127,12 +127,12 @@ public:
* @param owner_process The parent process for the thread, if null, it's a kernel thread
* @return A shared pointer to the newly created thread
*/
- [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> Create(
+ [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> CreateThread(
Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point,
u32 priority, u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process);
/**
- * Creates and returns a new thread. The new thread is immediately scheduled
+ * Creates and returns a new thread, with a specified entry point.
* @param system The instance of the whole system
* @param name The friendly name desired for the thread
* @param entry_point The address at which the thread should start execution
@@ -145,11 +145,27 @@ public:
* @param thread_start_parameter The parameter which will passed to host context on init
* @return A shared pointer to the newly created thread
*/
- [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> Create(
+ [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> CreateThread(
Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point,
u32 priority, u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process,
std::function<void(void*)>&& thread_start_func, void* thread_start_parameter);
+ /**
+ * Creates and returns a new thread for the emulated "user" process.
+ * @param system The instance of the whole system
+ * @param name The friendly name desired for the thread
+ * @param entry_point The address at which the thread should start execution
+ * @param priority The thread's priority
+ * @param arg User data to pass to the thread
+ * @param processor_id The ID(s) of the processors on which the thread is desired to be run
+ * @param stack_top The address of the thread's stack top
+ * @param owner_process The parent process for the thread, if null, it's a kernel thread
+ * @return A shared pointer to the newly created thread
+ */
+ [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> CreateUserThread(
+ Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point,
+ u32 priority, u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process);
+
[[nodiscard]] std::string GetName() const override {
return name;
}
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 331cf3a60..780008b08 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -181,9 +181,9 @@ struct KernelCore::Impl {
std::string name = "Suspend Thread Id:" + std::to_string(i);
std::function<void(void*)> init_func = Core::CpuManager::GetSuspendThreadStartFunc();
void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
- auto thread_res = KThread::Create(system, ThreadType::HighPriority, std::move(name), 0,
- 0, 0, static_cast<u32>(i), 0, nullptr,
- std::move(init_func), init_func_parameter);
+ auto thread_res = KThread::CreateThread(
+ system, ThreadType::HighPriority, std::move(name), 0, 0, 0, static_cast<u32>(i), 0,
+ nullptr, std::move(init_func), init_func_parameter);
suspend_threads[i] = std::move(thread_res).Unwrap();
}
@@ -221,10 +221,9 @@ struct KernelCore::Impl {
// Gets the dummy KThread for the caller, allocating a new one if this is the first time
KThread* GetHostDummyThread() {
const thread_local auto thread =
- KThread::Create(
+ KThread::CreateThread(
system, ThreadType::Main, fmt::format("DummyThread:{}", GetHostThreadId()), 0,
- KThread::DefaultThreadPriority, 0, static_cast<u32>(3), 0, nullptr,
- []([[maybe_unused]] void* arg) { UNREACHABLE(); }, nullptr)
+ KThread::DefaultThreadPriority, 0, static_cast<u32>(3), 0, nullptr)
.Unwrap();
return thread.get();
}
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 73b85d6f9..9d5956ead 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -40,8 +40,9 @@ namespace {
void SetupMainThread(Core::System& system, Process& owner_process, u32 priority, VAddr stack_top) {
const VAddr entry_point = owner_process.PageTable().GetCodeRegionStart();
ASSERT(owner_process.GetResourceLimit()->Reserve(LimitableResource::Threads, 1));
- auto thread_res = KThread::Create(system, ThreadType::User, "main", entry_point, priority, 0,
- owner_process.GetIdealCoreId(), stack_top, &owner_process);
+ auto thread_res =
+ KThread::CreateUserThread(system, ThreadType::User, "main", entry_point, priority, 0,
+ owner_process.GetIdealCoreId(), stack_top, &owner_process);
std::shared_ptr<KThread> thread = std::move(thread_res).Unwrap();
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index cc8fa6576..326d3b9ec 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1532,8 +1532,9 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e
std::shared_ptr<KThread> thread;
{
KScopedLightLock lk{process.GetStateLock()};
- CASCADE_RESULT(thread, KThread::Create(system, ThreadType::User, "", entry_point, priority,
- arg, core_id, stack_bottom, &process));
+ CASCADE_RESULT(thread,
+ KThread::CreateUserThread(system, ThreadType::User, "", entry_point,
+ priority, arg, core_id, stack_bottom, &process));
}
const auto new_thread_handle = process.GetHandleTable().Create(thread);
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp
index 681e93468..526bfa110 100644
--- a/src/core/network/network.cpp
+++ b/src/core/network/network.cpp
@@ -7,6 +7,7 @@
#include <limits>
#include <utility>
#include <vector>
+#include "common/common_funcs.h"
#ifdef _WIN32
#define _WINSOCK_DEPRECATED_NO_WARNINGS // gethostname
@@ -90,15 +91,36 @@ LINGER MakeLinger(bool enable, u32 linger_value) {
return value;
}
-int LastError() {
- return WSAGetLastError();
-}
-
bool EnableNonBlock(SOCKET fd, bool enable) {
u_long value = enable ? 1 : 0;
return ioctlsocket(fd, FIONBIO, &value) != SOCKET_ERROR;
}
+Errno TranslateNativeError(int e) {
+ switch (e) {
+ case WSAEBADF:
+ return Errno::BADF;
+ case WSAEINVAL:
+ return Errno::INVAL;
+ case WSAEMFILE:
+ return Errno::MFILE;
+ case WSAENOTCONN:
+ return Errno::NOTCONN;
+ case WSAEWOULDBLOCK:
+ return Errno::AGAIN;
+ case WSAECONNREFUSED:
+ return Errno::CONNREFUSED;
+ case WSAEHOSTUNREACH:
+ return Errno::HOSTUNREACH;
+ case WSAENETDOWN:
+ return Errno::NETDOWN;
+ case WSAENETUNREACH:
+ return Errno::NETUNREACH;
+ default:
+ return Errno::OTHER;
+ }
+}
+
#elif YUZU_UNIX // ^ _WIN32 v YUZU_UNIX
using SOCKET = int;
@@ -108,9 +130,6 @@ using ULONG = u64;
constexpr SOCKET INVALID_SOCKET = -1;
constexpr SOCKET SOCKET_ERROR = -1;
-constexpr int WSAEWOULDBLOCK = EAGAIN;
-constexpr int WSAENOTCONN = ENOTCONN;
-
constexpr int SD_RECEIVE = SHUT_RD;
constexpr int SD_SEND = SHUT_WR;
constexpr int SD_BOTH = SHUT_RDWR;
@@ -162,10 +181,6 @@ linger MakeLinger(bool enable, u32 linger_value) {
return value;
}
-int LastError() {
- return errno;
-}
-
bool EnableNonBlock(int fd, bool enable) {
int flags = fcntl(fd, F_GETFD);
if (flags == -1) {
@@ -179,8 +194,43 @@ bool EnableNonBlock(int fd, bool enable) {
return fcntl(fd, F_SETFD, flags) == 0;
}
+Errno TranslateNativeError(int e) {
+ switch (e) {
+ case EBADF:
+ return Errno::BADF;
+ case EINVAL:
+ return Errno::INVAL;
+ case EMFILE:
+ return Errno::MFILE;
+ case ENOTCONN:
+ return Errno::NOTCONN;
+ case EAGAIN:
+ return Errno::AGAIN;
+ case ECONNREFUSED:
+ return Errno::CONNREFUSED;
+ case EHOSTUNREACH:
+ return Errno::HOSTUNREACH;
+ case ENETDOWN:
+ return Errno::NETDOWN;
+ case ENETUNREACH:
+ return Errno::NETUNREACH;
+ default:
+ return Errno::OTHER;
+ }
+}
+
#endif
+Errno GetAndLogLastError() {
+#ifdef _WIN32
+ int e = WSAGetLastError();
+#else
+ int e = errno;
+#endif
+ LOG_ERROR(Network, "Socket operation error: {}", NativeErrorToString(e));
+ return TranslateNativeError(e);
+}
+
int TranslateDomain(Domain domain) {
switch (domain) {
case Domain::INET:
@@ -290,9 +340,7 @@ Errno SetSockOpt(SOCKET fd, int option, T value) {
if (result != SOCKET_ERROR) {
return Errno::SUCCESS;
}
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
+ return GetAndLogLastError();
}
} // Anonymous namespace
@@ -308,14 +356,12 @@ NetworkInstance::~NetworkInstance() {
std::pair<IPv4Address, Errno> GetHostIPv4Address() {
std::array<char, 256> name{};
if (gethostname(name.data(), static_cast<int>(name.size()) - 1) == SOCKET_ERROR) {
- UNIMPLEMENTED_MSG("Unhandled gethostname error");
- return {IPv4Address{}, Errno::SUCCESS};
+ return {IPv4Address{}, GetAndLogLastError()};
}
hostent* const ent = gethostbyname(name.data());
if (!ent) {
- UNIMPLEMENTED_MSG("Unhandled gethostbyname error");
- return {IPv4Address{}, Errno::SUCCESS};
+ return {IPv4Address{}, GetAndLogLastError()};
}
if (ent->h_addr_list == nullptr) {
UNIMPLEMENTED_MSG("No addr provided in hostent->h_addr_list");
@@ -359,9 +405,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) {
ASSERT(result == SOCKET_ERROR);
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {-1, Errno::SUCCESS};
+ return {-1, GetAndLogLastError()};
}
Socket::~Socket() {
@@ -380,9 +424,7 @@ Errno Socket::Initialize(Domain domain, Type type, Protocol protocol) {
return Errno::SUCCESS;
}
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
+ return GetAndLogLastError();
}
std::pair<Socket::AcceptResult, Errno> Socket::Accept() {
@@ -391,9 +433,7 @@ std::pair<Socket::AcceptResult, Errno> Socket::Accept() {
const SOCKET new_socket = accept(fd, &addr, &addrlen);
if (new_socket == INVALID_SOCKET) {
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {AcceptResult{}, Errno::SUCCESS};
+ return {AcceptResult{}, GetAndLogLastError()};
}
AcceptResult result;
@@ -412,23 +452,14 @@ Errno Socket::Connect(SockAddrIn addr_in) {
return Errno::SUCCESS;
}
- switch (const int ec = LastError()) {
- case WSAEWOULDBLOCK:
- LOG_DEBUG(Service, "EAGAIN generated");
- return Errno::AGAIN;
- default:
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
- }
+ return GetAndLogLastError();
}
std::pair<SockAddrIn, Errno> Socket::GetPeerName() {
sockaddr addr;
socklen_t addrlen = sizeof(addr);
if (getpeername(fd, &addr, &addrlen) == SOCKET_ERROR) {
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {SockAddrIn{}, Errno::SUCCESS};
+ return {SockAddrIn{}, GetAndLogLastError()};
}
ASSERT(addrlen == sizeof(sockaddr_in));
@@ -439,9 +470,7 @@ std::pair<SockAddrIn, Errno> Socket::GetSockName() {
sockaddr addr;
socklen_t addrlen = sizeof(addr);
if (getsockname(fd, &addr, &addrlen) == SOCKET_ERROR) {
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {SockAddrIn{}, Errno::SUCCESS};
+ return {SockAddrIn{}, GetAndLogLastError()};
}
ASSERT(addrlen == sizeof(sockaddr_in));
@@ -454,9 +483,7 @@ Errno Socket::Bind(SockAddrIn addr) {
return Errno::SUCCESS;
}
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
+ return GetAndLogLastError();
}
Errno Socket::Listen(s32 backlog) {
@@ -464,9 +491,7 @@ Errno Socket::Listen(s32 backlog) {
return Errno::SUCCESS;
}
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
+ return GetAndLogLastError();
}
Errno Socket::Shutdown(ShutdownHow how) {
@@ -489,14 +514,7 @@ Errno Socket::Shutdown(ShutdownHow how) {
return Errno::SUCCESS;
}
- switch (const int ec = LastError()) {
- case WSAENOTCONN:
- LOG_ERROR(Service, "ENOTCONN generated");
- return Errno::NOTCONN;
- default:
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
- }
+ return GetAndLogLastError();
}
std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) {
@@ -509,17 +527,7 @@ std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) {
return {static_cast<s32>(result), Errno::SUCCESS};
}
- switch (const int ec = LastError()) {
- case WSAEWOULDBLOCK:
- LOG_DEBUG(Service, "EAGAIN generated");
- return {-1, Errno::AGAIN};
- case WSAENOTCONN:
- LOG_ERROR(Service, "ENOTCONN generated");
- return {-1, Errno::NOTCONN};
- default:
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {0, Errno::SUCCESS};
- }
+ return {-1, GetAndLogLastError()};
}
std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr) {
@@ -541,17 +549,7 @@ std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, Sock
return {static_cast<s32>(result), Errno::SUCCESS};
}
- switch (const int ec = LastError()) {
- case WSAEWOULDBLOCK:
- LOG_DEBUG(Service, "EAGAIN generated");
- return {-1, Errno::AGAIN};
- case WSAENOTCONN:
- LOG_ERROR(Service, "ENOTCONN generated");
- return {-1, Errno::NOTCONN};
- default:
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {-1, Errno::SUCCESS};
- }
+ return {-1, GetAndLogLastError()};
}
std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) {
@@ -564,18 +562,7 @@ std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) {
return {static_cast<s32>(result), Errno::SUCCESS};
}
- const int ec = LastError();
- switch (ec) {
- case WSAEWOULDBLOCK:
- LOG_DEBUG(Service, "EAGAIN generated");
- return {-1, Errno::AGAIN};
- case WSAENOTCONN:
- LOG_ERROR(Service, "ENOTCONN generated");
- return {-1, Errno::NOTCONN};
- default:
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {-1, Errno::SUCCESS};
- }
+ return {-1, GetAndLogLastError()};
}
std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message,
@@ -597,9 +584,7 @@ std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message,
return {static_cast<s32>(result), Errno::SUCCESS};
}
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return {-1, Errno::SUCCESS};
+ return {-1, GetAndLogLastError()};
}
Errno Socket::Close() {
@@ -642,9 +627,7 @@ Errno Socket::SetNonBlock(bool enable) {
if (EnableNonBlock(fd, enable)) {
return Errno::SUCCESS;
}
- const int ec = LastError();
- UNREACHABLE_MSG("Unhandled host socket error={}", ec);
- return Errno::SUCCESS;
+ return GetAndLogLastError();
}
bool Socket::IsOpened() const {
diff --git a/src/core/network/network.h b/src/core/network/network.h
index 76b2821f2..bd30f1899 100644
--- a/src/core/network/network.h
+++ b/src/core/network/network.h
@@ -7,6 +7,7 @@
#include <array>
#include <utility>
+#include "common/common_funcs.h"
#include "common/common_types.h"
namespace Network {
@@ -21,6 +22,11 @@ enum class Errno {
MFILE,
NOTCONN,
AGAIN,
+ CONNREFUSED,
+ HOSTUNREACH,
+ NETDOWN,
+ NETUNREACH,
+ OTHER,
};
/// Address families