mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-01-30 19:13:09 +00:00
Yellow squiggly lines begone! Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes. If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed. The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports. Not everything is removed, but the cleanup should be substantial enough. Because this done on Linux, code that isn't used on it is mostly untouched. (Hopefully no open PR is depending on these imports...)
57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
// Copyright 2021 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "Common/SocketContext.h"
|
|
#ifdef _WIN32
|
|
#include "Common/Logging/Log.h"
|
|
#include "Common/Network.h"
|
|
#endif
|
|
|
|
namespace Common
|
|
{
|
|
#ifdef _WIN32
|
|
SocketContext::SocketContext()
|
|
{
|
|
std::lock_guard<std::mutex> g(s_lock);
|
|
if (s_num_objects == 0)
|
|
{
|
|
const int ret = WSAStartup(MAKEWORD(2, 2), &s_data);
|
|
if (ret == 0)
|
|
{
|
|
INFO_LOG_FMT(COMMON, "WSAStartup succeeded, wVersion={}.{}, wHighVersion={}.{}",
|
|
int(LOBYTE(s_data.wVersion)), int(HIBYTE(s_data.wVersion)),
|
|
int(LOBYTE(s_data.wHighVersion)), int(HIBYTE(s_data.wHighVersion)));
|
|
}
|
|
else
|
|
{
|
|
// The WSAStartup function directly returns the extended error code in the return value.
|
|
// A call to the WSAGetLastError function is not needed and should not be used.
|
|
//
|
|
// Source:
|
|
// https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup
|
|
ERROR_LOG_FMT(COMMON, "WSAStartup failed with error {}: {}", ret,
|
|
Common::DecodeNetworkError(ret));
|
|
}
|
|
}
|
|
s_num_objects++;
|
|
}
|
|
SocketContext::~SocketContext()
|
|
{
|
|
std::lock_guard<std::mutex> g(s_lock);
|
|
s_num_objects--;
|
|
if (s_num_objects == 0)
|
|
{
|
|
WSACleanup();
|
|
}
|
|
}
|
|
|
|
std::mutex SocketContext::s_lock;
|
|
size_t SocketContext::s_num_objects = 0;
|
|
WSADATA SocketContext::s_data;
|
|
|
|
#else
|
|
SocketContext::SocketContext() = default;
|
|
SocketContext::~SocketContext() = default;
|
|
#endif
|
|
} // namespace Common
|