summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/internal_network/socket_proxy.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/core/internal_network/socket_proxy.cpp b/src/core/internal_network/socket_proxy.cpp
index 7ce22dbfa..49d067f4c 100644
--- a/src/core/internal_network/socket_proxy.cpp
+++ b/src/core/internal_network/socket_proxy.cpp
@@ -32,6 +32,7 @@ void ProxySocket::HandleProxyPacket(const ProxyPacket& packet) {
32 32
33template <typename T> 33template <typename T>
34Errno ProxySocket::SetSockOpt(SOCKET fd_, int option, T value) { 34Errno ProxySocket::SetSockOpt(SOCKET fd_, int option, T value) {
35 LOG_DEBUG(Network, "(STUBBED) called");
35 return Errno::SUCCESS; 36 return Errno::SUCCESS;
36} 37}
37 38
@@ -95,8 +96,12 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message,
95 ASSERT(flags == 0); 96 ASSERT(flags == 0);
96 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); 97 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
97 98
99 // TODO (flTobi): Verify the timeout behavior and break when connection is lost
98 const auto timestamp = std::chrono::steady_clock::now(); 100 const auto timestamp = std::chrono::steady_clock::now();
99 101 // When receive_timeout is set to zero, the socket is supposed to wait indefinitely until a
102 // packet arrives. In order to prevent lost packets from hanging the emulation thread, we set
103 // the timeout to 5s instead
104 const auto timeout = receive_timeout == 0 ? 5000 : receive_timeout;
100 while (true) { 105 while (true) {
101 { 106 {
102 std::lock_guard guard(packets_mutex); 107 std::lock_guard guard(packets_mutex);
@@ -109,19 +114,13 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message,
109 return {-1, Errno::AGAIN}; 114 return {-1, Errno::AGAIN};
110 } 115 }
111 116
112 // TODO: break if socket connection is lost
113
114 std::this_thread::yield(); 117 std::this_thread::yield();
115 118
116 if (receive_timeout == 0) {
117 continue;
118 }
119
120 const auto time_diff = std::chrono::steady_clock::now() - timestamp; 119 const auto time_diff = std::chrono::steady_clock::now() - timestamp;
121 const auto time_diff_ms = 120 const auto time_diff_ms =
122 std::chrono::duration_cast<std::chrono::milliseconds>(time_diff).count(); 121 std::chrono::duration_cast<std::chrono::milliseconds>(time_diff).count();
123 122
124 if (time_diff_ms > receive_timeout) { 123 if (time_diff_ms > timeout) {
125 return {-1, Errno::TIMEDOUT}; 124 return {-1, Errno::TIMEDOUT};
126 } 125 }
127 } 126 }