diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 14a1863fcf..4a3623d4e8 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -110,6 +110,8 @@ add_library(common SettingsHandler.h SFMLHelper.cpp SFMLHelper.h + SocketContext.cpp + SocketContext.h SPSCQueue.h StringUtil.cpp StringUtil.h diff --git a/Source/Core/Common/SocketContext.cpp b/Source/Core/Common/SocketContext.cpp new file mode 100644 index 0000000000..e9174bc0d9 --- /dev/null +++ b/Source/Core/Common/SocketContext.cpp @@ -0,0 +1,22 @@ +// Copyright 2021 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Common/SocketContext.h" + +namespace Common +{ +#ifdef _WIN32 +SocketContext::SocketContext() +{ + static_cast(WSAStartup(MAKEWORD(2, 2), &m_data)); +} +SocketContext::~SocketContext() +{ + WSACleanup(); +} +#else +SocketContext::SocketContext() = default; +SocketContext::~SocketContext() = default; +#endif +} // namespace Common diff --git a/Source/Core/Common/SocketContext.h b/Source/Core/Common/SocketContext.h new file mode 100644 index 0000000000..1645201f1f --- /dev/null +++ b/Source/Core/Common/SocketContext.h @@ -0,0 +1,30 @@ +// Copyright 2021 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#ifdef _WIN32 +#include +#endif + +namespace Common +{ +class SocketContext +{ +public: + SocketContext(); + ~SocketContext(); + + SocketContext(const SocketContext&) = delete; + SocketContext(SocketContext&&) = delete; + + SocketContext& operator=(const SocketContext&) = delete; + SocketContext& operator=(SocketContext&&) = delete; + +private: +#ifdef _WIN32 + WSADATA m_data; +#endif +}; +} // namespace Common diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index ae228c0733..d78534993a 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -142,6 +142,7 @@ + @@ -718,6 +719,7 @@ +