summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2022-08-13 20:11:01 +0200
committerFearlessTobi <thm.frey@gmail.com>2022-08-15 20:25:42 +0200
commit72b90a5bbf7a9308f7172f38be88e29bab58a21b (patch)
tree981faf5a3a9c568b0ff00ba0ae1511e73368e649
parentyuzu: Fix crash on shutdown (diff)
downloadyuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.tar
yuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.tar.gz
yuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.tar.bz2
yuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.tar.lz
yuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.tar.xz
yuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.tar.zst
yuzu-72b90a5bbf7a9308f7172f38be88e29bab58a21b.zip
-rw-r--r--src/core/internal_network/socket_proxy.cpp46
-rw-r--r--src/core/internal_network/socket_proxy.h13
-rw-r--r--src/dedicated_room/CMakeLists.txt4
-rw-r--r--src/dedicated_room/yuzu_room.cpp (renamed from src/dedicated_room/yuzu-room.cpp)0
-rw-r--r--src/dedicated_room/yuzu_room.rc (renamed from src/dedicated_room/yuzu-room.rc)0
5 files changed, 31 insertions, 32 deletions
diff --git a/src/core/internal_network/socket_proxy.cpp b/src/core/internal_network/socket_proxy.cpp
index 216893ba1..7ce22dbfa 100644
--- a/src/core/internal_network/socket_proxy.cpp
+++ b/src/core/internal_network/socket_proxy.cpp
@@ -14,10 +14,6 @@ namespace Network {
ProxySocket::ProxySocket(RoomNetwork& room_network_) noexcept : room_network{room_network_} {}
-ProxySocket::ProxySocket(ProxySocket&& rhs) noexcept : room_network{rhs.room_network} {
- fd = std::exchange(rhs.fd, INVALID_SOCKET);
-}
-
ProxySocket::~ProxySocket() {
if (fd == INVALID_SOCKET) {
return;
@@ -36,7 +32,6 @@ void ProxySocket::HandleProxyPacket(const ProxyPacket& packet) {
template <typename T>
Errno ProxySocket::SetSockOpt(SOCKET fd_, int option, T value) {
- socket_options[option] = reinterpret_cast<const char*>(&value);
return Errno::SUCCESS;
}
@@ -100,27 +95,36 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message,
ASSERT(flags == 0);
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
- {
- std::lock_guard guard(packets_mutex);
- if (received_packets.size() > 0) {
- return ReceivePacket(flags, message, addr, message.size());
+ const auto timestamp = std::chrono::steady_clock::now();
+
+ while (true) {
+ {
+ std::lock_guard guard(packets_mutex);
+ if (received_packets.size() > 0) {
+ return ReceivePacket(flags, message, addr, message.size());
+ }
}
- }
- if (blocking) {
- if (receive_timeout > 0) {
- std::this_thread::sleep_for(std::chrono::milliseconds(receive_timeout));
+ if (!blocking) {
+ return {-1, Errno::AGAIN};
}
- } else {
- return {-1, Errno::AGAIN};
- }
- std::lock_guard guard(packets_mutex);
- if (received_packets.size() > 0) {
- return ReceivePacket(flags, message, addr, message.size());
- }
+ // TODO: break if socket connection is lost
+
+ std::this_thread::yield();
+
+ if (receive_timeout == 0) {
+ continue;
+ }
- return {-1, Errno::TIMEDOUT};
+ const auto time_diff = std::chrono::steady_clock::now() - timestamp;
+ const auto time_diff_ms =
+ std::chrono::duration_cast<std::chrono::milliseconds>(time_diff).count();
+
+ if (time_diff_ms > receive_timeout) {
+ return {-1, Errno::TIMEDOUT};
+ }
+ }
}
std::pair<s32, Errno> ProxySocket::ReceivePacket(int flags, std::vector<u8>& message,
diff --git a/src/core/internal_network/socket_proxy.h b/src/core/internal_network/socket_proxy.h
index ad917cac3..f12b5f567 100644
--- a/src/core/internal_network/socket_proxy.h
+++ b/src/core/internal_network/socket_proxy.h
@@ -7,6 +7,7 @@
#include <vector>
#include <queue>
+#include "common/common_funcs.h"
#include "core/internal_network/sockets.h"
#include "network/network.h"
@@ -14,17 +15,12 @@ namespace Network {
class ProxySocket : public SocketBase {
public:
+ YUZU_NON_COPYABLE(ProxySocket);
+ YUZU_NON_MOVEABLE(ProxySocket);
+
explicit ProxySocket(RoomNetwork& room_network_) noexcept;
~ProxySocket() override;
- ProxySocket(const ProxySocket&) = delete;
- ProxySocket& operator=(const ProxySocket&) = delete;
-
- ProxySocket(ProxySocket&& rhs) noexcept;
-
- // Avoid closing sockets implicitly
- ProxySocket& operator=(ProxySocket&&) noexcept = delete;
-
void HandleProxyPacket(const ProxyPacket& packet) override;
Errno Initialize(Domain domain, Type type, Protocol socket_protocol) override;
@@ -87,7 +83,6 @@ private:
bool closed = false;
u32 send_timeout = 0;
u32 receive_timeout = 0;
- std::map<int, const char*> socket_options;
bool is_bound = false;
SockAddrIn local_endpoint{};
bool blocking = true;
diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt
index 7b9dc9c04..b674b915b 100644
--- a/src/dedicated_room/CMakeLists.txt
+++ b/src/dedicated_room/CMakeLists.txt
@@ -4,8 +4,8 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
add_executable(yuzu-room
- yuzu-room.cpp
- yuzu-room.rc
+ yuzu_room.cpp
+ yuzu_room.rc
)
create_target_directory_groups(yuzu-room)
diff --git a/src/dedicated_room/yuzu-room.cpp b/src/dedicated_room/yuzu_room.cpp
index 482e772fb..482e772fb 100644
--- a/src/dedicated_room/yuzu-room.cpp
+++ b/src/dedicated_room/yuzu_room.cpp
diff --git a/src/dedicated_room/yuzu-room.rc b/src/dedicated_room/yuzu_room.rc
index a08957684..a08957684 100644
--- a/src/dedicated_room/yuzu-room.rc
+++ b/src/dedicated_room/yuzu_room.rc